Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process for writing PHP page on the fly 2

Status
Not open for further replies.

jacksondorado

IS-IT--Management
Joined
Apr 12, 2001
Messages
135
Location
US
I am hoping someone could help me with the overview of creating a new PHP page for each new user to a site. I hope this makes sense...

Once the new user fills out a form, I create a folder using their username and a new index.php file in that folder. I would like to execute PHP functions on that new user home page. I tried fwrite but can only get basic text to show up. I am using mySQL to store the user info.

Can I have a set of functions saved that would write a dynamic page and call the file after creating the new page? Does it have to be stored in the DB or can it just be a file to include?

I want each new user page to load with a set of components for the user to have.
thanks.
 
I tried fwrite but can only get basic text to show up.
What do you mean? It must have written the file, did it?

You can redirect to the newly written file using the header directive. Just be careful that there is no output prior to the header("Location: ".$newlocation).

You can include standard function libraries from a common folder using the include() syntax.
 
well, u will always have to use fwrite... and fwrite doesn't see if it is parsing php or anything, just treats it as plain text.

u will have to have a template file stored in you base path, something like:

Code:
template.php:

<?
  $user_id = "{USERID}";

  echo "bla bla";

  functions_u_use();

  etc

?>

(i'm assuming that every user has a unique id, as u are storing them in mySQL tables)

then, everytime a user registers, the signup script loads the template.php file through normal fopen, "fread s" it's contents to a temporary var, u perform a str_replace on that {USERID} that will be inside the var, and will be replaced by the actual user id, and then write that var's contents to the new index.php file. then the index.php file will load and display whatever you want based on that user id. you can have more fields to replace, and may use whatever syntax you like, i just used that for the example ;)

jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
Thanks for the help. I am still a little confused but I understand the direction you explained jamesp0tter.

I am still unclear on how and when the template.php functions will execute. To answer DRJ478, it did write the file but only the plain text.

I have in the new user login script:

#############
mkdir ($newname,0755);
$fileHome = fopen ("$newname/index.php","w");
fwrite($fileHome,"hello world");
fclose ($fileHome);

header("Location:$newname/index.php");
####################

I want to have a standard HTML page with functionality created in the $newname directory each time a new user registers. I'm at a more basic PHP understanding so I'll need to play with jamesp0tter's process. When the template.php is written to a var, can an entire HTML page be stored in the var? graphics and all?

Does template.php get executed upon fopen or fread call?

thanks again.
 
HTML pages don't store graphics. They refer to them by <img> tags. There is no binary information in an HTML page.
As long as the path to the graphics resolve it's fine.

Plain text:
PHP code is plain text, HTML is plain text. A PHP script is interpreted when it is requested e.g. by the web server or invoked by the command line. Writing a file that happens to contain PHP code is straight forward.

A page of HTML can easily be held in the memory unless you have a computer that subsribes to Bill Gates' belief that 640K is plenty of memory (Who would need more?) ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top