Page 1 of 1

Making redirect write to file

Posted: Thu Jan 26, 2006 9:23 am
by waradmin
I want to be able to have (when people sign up for my site) a directory created, a index.htm file copied to it thats blank and then values written to it to do a <?php header("Location: ")... redirect

Currently i have

Code: Select all

mkdir("../".$_POST['user']."", 0777);
				
$file = 'index.htm';
$newfile = '../'.$_POST['user'].'/index.htm';

if (!copy($file, $newfile)) {
   echo "failed to copy $file...\n";
}

$filename = '../'.$_POST['user'].'/index.htm';
$somecontent ='<? header("Location: http://www.myopenspace.net/user/?P="'.$_POST['user'].'""); exit; ?>';
if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   
   fclose($handle);

} else {

}
But that doesnt work. Help would be appreciated.

-steve

Posted: Thu Jan 26, 2006 8:13 pm
by raghavan20
Post the link to the working file with errors you came up with...

Posted: Thu Jan 26, 2006 8:45 pm
by John Cartwright
This doesn't look like a very good setup, if I understand the overall purpose of this.
I think what your after is something along the lines of mod rewrite, that way you don't have to actually create a directory/file for each individual user, have a single file to handle ALL users, as well as maintain a pretty link :)

so lets say the user visits

http://domain.com/username

you could setup a simple mod rewrite rule

Code: Select all

RewriteRule ^/([A-Za-z]+)$ /user.php?P=$1
and in user.php make the appropriate database (or wherever their info is stored) calls to retrive the user information