简体   繁体   中英

PHP user profile page

Im trying to make a website with users on it, and I'm trying to create a script so that whenever a new user registers it will automatically create a user folder and profile for them but when I try to register it doesn't create the files,
could someone please help me with this, Thanks

 <?php include "inc/header.php"; $newfolder = $username; if (!mkdir($newfolder, 0777, true)) { die('Failed to create folders...'); } $pagename = $username; $newFileName = './u/'.$username.'/'.$pagename.".php"; $newFileContent = '<?php echo "something..."; ?>'; ?>

To make a directory/file

if (!file_exists("parent_folder/$username")) {
//Create a file with read write execute PERMISSIONS ENABLED 
//Please check :  your parent folder also must have 0777 permissions to avoid any kind of read write error
        mkdir("parent_folder/$username", 0777);
//now u have to create a FILE with .php
//now this file_put_contents is VERY importnant !
$pagename = $username ;
$newFileName = './parent_folder/$username/'.$pagename.".php";
$newFileContent = '<?php echo "something..."; ?>';

if (file_put_contents($newFileName, $newFileContent) !== false) {
//notify file is created 
    echo "File created (" . basename($newFileName) . ")";
} else {
//notify u have error
    echo "Cannot create file (" . basename($newFileName) . ")";
}

//now create ur .php file in user folder
        }
       else {
    echo "Your parent folder does not exist"
    }

Now the possible error and some tips

1) Most of people do fopen("filename_with_PATH", "w") and expect that file will be generated in PATH folder ! Some times it might fall wrong (depends on version)

fopen is meant to create a file in the directory where your php resides

2) check ur php permission in php.ini if u dont give php permission to write,remote access then u might get some errors (it will be displayed that u have error in my script)

3)For more info and tinkering file_put_contents

Hope this will be helpful for you ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM