views:

21

answers:

2

When a user registers I am wondering how to create them a dynamic directory (which will show they're profile), such as Facebook / MySpace.

I want the directory to be that of their username. The username is stored on the database.

Technologies being used

Database: MySQL

Front End: PHP

I've looked at using the PHP MKDIR command to create an individual directory, but i don't really want the FTP to be overrun with folders

A: 

If your code is running under Apache, you should look into mod_rewrite and make the "folders" virtual.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Ole Melhus
A: 

Facebook doesn't give users their own directory. Giving a user their own directory takes lots of server resources, lots of effort on the back-end, and after you have several million users the clutter in the file-allocation table would cause page loads to be horrendous. Then take into account all the wasted disk space since hard drives operate on a paging system, AND you'd need an index.html file for each directory...

What Facebook does instead is write a line to a .htaccess file. When a user says they want www.facebook.com/username, facebook adds the following:

RewriteRule username profile.php?id=<user id>

There are better ways to do this, even. You could have EVERYTHING redirect to parse_request.php, which will determine if you were requesting a user's specific page, or if you were requesting a static page (like welcome.php) which shouldn't change.

steven_desu
That looks exactly what i need. Something i don't understand about this process though is the ?id=<user id> bit. Im not sure at all about how to code it or how it works.
itsphil
Whenever you put a question mark after a URL it sends the data as a "GET" request. In PHP you can access these variables from the `$_GET[]` variable. So for instance, you could say something like `if($_GET['id'] == 1){ echo "Welcome back, admin!"; }` (assuming "admin" is user 1). This id is then usually included in a database query to find information about the desired user. Something like `SELECT * FROM users WHERE id == $_GET['id']`
steven_desu