Making redirect write to file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Making redirect write to file

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Post the link to the working file with errors you came up with...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply