Page 1 of 1

PHP - Username to Folder [SOLVED]

Posted: Sun Jun 11, 2006 10:51 pm
by tecktalkcm0391
I know to use mkdir(); to make a folder but I want to do a little more that that.
This is what I want to do:

When a user signs-up, a folder is created at domain.com/profiles/[the username]
and a standard php file is copied there from domain.com/profiles/defaultprofile.php
but the file is renamed to index.php. After that is done I want to make another folder at
domain.com/~[username], and then create another php file, which has a header which redirects
to domain.com/profiles/[the username].... which if i need to make another default page I can, but
I don't know how to make it so that it would foward to the right directory.

How would I do this all...

Posted: Sun Jun 11, 2006 11:09 pm
by Christopher
It seems like rather than creating directories and files, you could just use mod_rewrite and a Front Controller to do the same thing. Then you could keep the user's site data in a database which would probably be much easier to manage.

Posted: Sun Jun 11, 2006 11:11 pm
by tecktalkcm0391
Ok, yeah all of the data is already in a database, its like a public profile is what I was aiming to do.

Posted: Mon Jun 12, 2006 5:30 am
by ed209
I had this issue a while ago.... here's a possible solution:

viewtopic.php?t=40707&highlight=

Posted: Mon Jun 12, 2006 6:01 am
by jayshields
aborint has the best idea.

If you want users to access their profiles from a folder just have mod_rewrite redirect yourdomain.com/theusername to yourdomain.com/profile.php?user=theusername and then grab the username using $_GET and show the correct profile on the page.

Posted: Mon Jun 12, 2006 9:17 am
by nathanr

Code: Select all

mkdir($username);
$filename = $username.'/index.php';
$somecontent = "<?\n".'header("Location: domain.com/profiles/'.$username.'")'."\n?>\n";
   if (!$handle = fopen($filename, 'x')) {
         echo "Cannot open file ($filename)";
         exit;
   }
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
  
   echo "created profile for ".$username;
  
   fclose($handle);
I think this should do it, as per usual completely untested and written straight into the post 8O

Posted: Mon Jun 12, 2006 10:08 am
by tecktalkcm0391
I'll try it. Thanks!