SKANK!!!!! 5 Posting Pro in Training

i made a script to create a directory and file within the directory for someone who is registering at my site also knows as
www.socialemo.com/theirusername/index.php
but im stuck on the index.php file
I DONT KNOW HOW TO WRITE HTML AND PHP TO THE FILE
how am i supposed to write a page of html to the file?
and also i need some php script to it too
is it possible to write php to a file with fwrite or do i have to do something else entirely
*the reason i need php is the login check because the page isnt supposed to be accesses unless the person is logged in*

so i basically need to know how to include this into the fwrite script

<?php
require($_SERVER["DOCUMENT_ROOT"] . "/xxxxx/checkforlogedinscript.php");
?>

hhhhhhhhhhhhiiiiiiiiii  <a href="http://www.socialemo.com/xxxxx/signouts">sign out</a>
Hi, you are in the session...
???????????????????????????????????

and some tables and other html maybe a stylesheet include

AND THIS IS WHAT I HAVE SO FAR:

if(mkdir($documentroot ."/". $row['username'] , 0777))
{
 $contents = "uhhhhhhhh";
$profile = $documentroot ."/". $row['username'] ."/index.php" ;
$fh = fopen($profile, 'w') or die("can't open file");
$contents = "uhhhhh\n";
fwrite($fh, $contents);
fclose($fh);
echo "<br> You can access your profile at <a href=\"http://www.socialemo.com/" . $row[username] . "\">www.socialemo.com/$row[username]</a> <br>";
}
else
{
   echo "There was a problem. Please <a href='http://www.socialemo.com/feedback.php'>contact</a> the administrator. ";

it works.. but i dont know how to put the php and stylesheets in and tables and stuff can anyone help me????