justinede Posted June 25, 2009 Share Posted June 25, 2009 Hello All, My login system has user a user page for each user that is created. Currently I have to manually make the page but I would like to automate this process. I make users on my admin page. Its very simple just a username and password is inserted. Here is the code for that add user page: <?php session_start(); if($_SESSION['myusername'] !== "Justin"){ header("location:http://justinledelson.com/includes/errors/unauthorized.php"); } else { } ?> <? //initilize PHP //then connect as user //change user and password to your mySQL name and password mysql_connect("****","******","******"); //select which database you want to edit mysql_select_db("justin_client"); //convert all the posts to variables: $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $result=MYSQL_QUERY("INSERT INTO `members` VALUES ('NULL', '$myusername', '$mypassword')"); //confirm echo "Query Finished"; ?> Some where after the username and password is added to the database I would like a script that makes a page named after $myusername. If at all possible, I would also like that page to have code in it. Your help will be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
chmpdog Posted June 25, 2009 Share Posted June 25, 2009 what would their page output? you could do a mod_rewrite and make it a dynamic page if the output allows it Quote Link to comment Share on other sites More sharing options...
justinede Posted June 25, 2009 Author Share Posted June 25, 2009 huh? their page output? i dont need a dynamic page, i have static pages for each user. Quote Link to comment Share on other sites More sharing options...
joel24 Posted June 25, 2009 Share Posted June 25, 2009 google! http://www.vipercreations.com/tutorials/PHP/25/ Quote Link to comment Share on other sites More sharing options...
justinede Posted June 25, 2009 Author Share Posted June 25, 2009 This is my code and I am getting this error. code: <?php session_start(); if($_SESSION['myusername'] !== "Justin"){ header("location:http://justinledelson.com/includes/errors/unauthorized.php"); } else { } ?> <? //initilize PHP //then connect as user //change user and password to your mySQL name and password mysql_connect("","",""); //select which database you want to edit mysql_select_db("justin_client"); //convert all the posts to variables: $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $result=MYSQL_QUERY("INSERT INTO `members` VALUES ('NULL', '$myusername', '$mypassword')"); //create userfile $file_directory = "/"; //the directory you want to store the new file in $file_name = strip_tags($_POST['$myusername']);//the file's name, stripped of any dangerous tags $file = $file_directory.$file_name.php; //this is the entire filename $create_file = fopen($file, "w+"); //create the new file if(!$create_file) { die("There was an error creating/opening the file! Make sure you have the correct permissions!\n"); } $chmod = chmod($file, 0755); //set the appropriate permissions. //attempt to set the permissions if(!$chmod) { echo("There was an error changing the permissions of the new file!\n"); //error changing the file's permissions } //attempt to write basic content to the file if (fwrite($create_file, "Content goes here!") === FALSE) { echo "Error writing to file: ($file)\n"; } fclose($create_file); echo "File was created successfully!\n"; //tell the user that the file has been created successfully exit; //exit the script //confirm echo "Query Finished"; ?> error: Warning: fopen(/php) [function.fopen]: failed to open stream: Permission denied in /home/content/j/u/s/justinledelson/html/login/users/adduser.php on line 34 Quote Link to comment Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 You have to change your CHMOD file attribute values. So you give that file permissions. Quote Link to comment Share on other sites More sharing options...
justinede Posted June 25, 2009 Author Share Posted June 25, 2009 isnt it set to 0755 in the script? shouldnt that work? it looks like its having issues making the file. I set the folder to 777 where its making the files. Quote Link to comment Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 isnt it set to 0755 in the script? shouldnt that work? it looks like its having issues making the file. I set the folder to 777 where its making the files. Try setting the file that's making the file (This one) to 777. Quote Link to comment Share on other sites More sharing options...
justinede Posted June 25, 2009 Author Share Posted June 25, 2009 still gave the same error. Quote Link to comment Share on other sites More sharing options...
justinede Posted June 25, 2009 Author Share Posted June 25, 2009 okay i fixed that error. now, it makes the file but it dosnt name it correctly. this is my updated code: <?php session_start(); if($_SESSION['myusername'] !== "Justin"){ header("location:http://justinledelson.com/includes/errors/unauthorized.php"); } else { } ?> <? //initilize PHP //then connect as user //change user and password to your mySQL name and password mysql_connect("justin_client.db.4191331.hostedresource.com","justin_client","Justin1"); //select which database you want to edit mysql_select_db("justin_client"); //convert all the posts to variables: $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $result=MYSQL_QUERY("INSERT INTO `members` VALUES ('NULL', '$myusername', '$mypassword')"); //create userfile $file_name = strip_tags($_POST['$myusername']);//the file's name, stripped of any dangerous tags $file = $file_name.php; //this is the entire filename $create_file = fopen($file, "w+"); //create the new file if(!$create_file) { die("There was an error creating/opening the file! Make sure you have the correct permissions!\n"); } $chmod = chmod($file, 0755); //set the appropriate permissions. //attempt to set the permissions if(!$chmod) { echo("There was an error changing the permissions of the new file!\n"); //error changing the file's permissions } //attempt to write basic content to the file if (fwrite($create_file, "Content goes here!") === FALSE) { echo "Error writing to file: ($file)\n"; } fclose($create_file); echo "File was created successfully!\n"; //tell the user that the file has been created successfully exit; //exit the script //confirm echo "Query Finished"; ?> instead of putting the username in the file name, it just names it php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.