Jump to content

[SOLVED] Automatically create page once user is added.


justinede

Recommended Posts

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.

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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.