By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

How do I give each registered user their own url using php?

P: 9
I am currently developing a site written in primarily PHP that allows users to signup and enter in some information. I would like to give them a unique url (web page) on my site that contains their information so it can be favorited, or quickly accessed by them. Do I need to create a folder in the virtual directory for each user ?
Feb 11 '08 #1
Share this Question
Share on Google+
11 Replies


harshmaul
Expert 100+
P: 490
Hi,
You could use url rewrites. (second time i mentioned this today!).

Anyway basically you make your page work using querystrings...
e.g. domain.com/index.php?user=harshmaul
and then you rewrite it to this....
domain.com/harshmaul/

Is that what you going for?

If thats what you want,check out mod rewrites in the htaccess.
Feb 11 '08 #2

ifedi
P: 60
I am currently developing a site written in primarily PHP that allows users to signup and enter in some information. I would like to give them a unique url (web page) on my site that contains their information so it can be favorited, or quickly accessed by them. Do I need to create a folder in the virtual directory for each user ?
I believe you can create a script to create a folder with the unique username as the name of the folder, and user-specific content (e.g. pictures) place therein.
On the other hand, there may be a couple of advantages in creating the page 'on the fly', by constructing an SQL to draw user-specific information into the user's page from a database, like so:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $sql="SELECT * FROM users_table WHERE user_id=".$id;
  3. $query=mysql_query($sql);
  4. $row_query=mysql_fetch_assoc($query);
  5. ?><html>
  6. <head>
  7. <title>My Site Home Page for <?php echo $username ?></title>
  8. </head>
  9. <body>
  10. <h1>Welcome to <?php echo $username?>'s Home Page!</h1>
  11. <div>Some stuff...</div>
  12. <div>Some other stuff...</div>
  13. </body>
  14. </html>
  15.  
Feb 12 '08 #3

harshmaul
Expert 100+
P: 490
Hi,
Ifedi has written some good logic. if you do get the page working using a "on the fly page" via the querystring as i mentioned above. we can re-write these into what appears to be a subfolder for that user.
Feb 12 '08 #4

ifedi
P: 60
If thats what you want,check out mod rewrites in the htaccess.
For those of us on Windows platform, how do we do the url rewrite?
Feb 12 '08 #5

harshmaul
Expert 100+
P: 490
hi,
are you still running apache? cos the rewrites are done using that....

in the root of your website (htdocs folder)...

create a file called...

".htaccess"

then in that file write the following....

Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^([.*])/$ index.php?login=$1
this will rewrite all pages that go like
www.domain.com/mylogin/
to
www.domain.com/index.php?login=mylogin

does that help?
Feb 12 '08 #6

ak1dnar
Expert 100+
P: 1,584
I am currently developing a site written in primarily PHP that allows users to signup and enter in some information. I would like to give them a unique url (web page) on my site that contains their information so it can be favorited, or quickly accessed by them. Do I need to create a folder in the virtual directory for each user ?
Hi jtm, rather than giving a solution, I'll ask a question !
if you are still planning to create separate directories for each user, do you planing to put individual pages for them on those directories?
ex:
http://www.domain.com/user_dir1/
http://www.domain.com/user_dir2/
is there separate web pages in those directories, for the users?

I think the most easiest solution has already provided for you.
Feb 12 '08 #7

Markus
Expert 5K+
P: 6,050
Hi jtm, rather than giving a solution, I'll ask a question !
if you are still planning to create separate directories for each user, do you planing to put individual pages for them on those directories?
ex:
http://www.domain.com/user_dir1/
http://www.domain.com/user_dir2/
is there separate web pages in those directories, for the users?

I think the most easiest solution has already provided for you.
But the heaviest..
imagine 4000 people do this.. that's 4000 folders, with 4000files, and possibly 4000 images and other content!
If you do this dynamically it saves you alot of hassle.
Feb 12 '08 #8

P: 9
I want to allow the user's url to be accessed by other members if given the link. So I won't be able to create it on the fly because it won't be based on the user that is signed on. Looking for something similar to how myspace lets it's users create a url page that can be hit directly without signing in. I assume when the user signs up I would create a folder/page at that point. Not sure how to do that.
Feb 12 '08 #9

harshmaul
Expert 100+
P: 490
Hi,
Thats fine, the user doesn't need to be logged in for you to use url rewriting.
you just send someone the link to .../index.php?name=myLogin, and if you just use that query string variable to display the page for that user.
Feb 12 '08 #10

ifedi
P: 60
hi,
are you still running apache? cos the rewrites are done using that....

in the root of your website (htdocs folder)...

create a file called...

".htaccess"

then in that file write the following....

Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^([.*])/$ index.php?login=$1
this will rewrite all pages that go like
www.domain.com/mylogin/
to
www.domain.com/index.php?login=mylogin

does that help?
I'm sorry. I forgot to say I'm running IIS on WinXp Sp2 on my primary developing machine, and I'd love to be able to achieve the url rewrite kind of thing on this system. However, thanks all the same, 'cause I intend to use the info you supplied on another system running apache on WinXp Sp2.
Thanks and regards,
Ifedi.
Feb 12 '08 #11

P: 9
Thanks all for your replies. I am going to try the rewrite.
Feb 12 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.