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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jtmphp
    New Member
    • Feb 2008
    • 9

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

    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 ?
  • harshmaul
    Recognized Expert Contributor
    • Jul 2007
    • 490

    #2
    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.

    Comment

    • ifedi
      New Member
      • Jan 2008
      • 60

      #3
      Originally posted by jtmphp
      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:
      Code:
      <?php 
      $sql="SELECT * FROM users_table WHERE user_id=".$id;
      $query=mysql_query($sql);
      $row_query=mysql_fetch_assoc($query);
      ?><html>
      <head>
      <title>My Site Home Page for <?php echo $username ?></title>
      </head>
      <body>
      <h1>Welcome to <?php echo $username?>'s Home Page!</h1>
      <div>Some stuff...</div>
      <div>Some other stuff...</div>
      </body>
      </html>

      Comment

      • harshmaul
        Recognized Expert Contributor
        • Jul 2007
        • 490

        #4
        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.

        Comment

        • ifedi
          New Member
          • Jan 2008
          • 60

          #5
          Originally posted by harshmaul
          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?

          Comment

          • harshmaul
            Recognized Expert Contributor
            • Jul 2007
            • 490

            #6
            missed out code tags oops

            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....

            Code:
            RewriteEngine on
            RewriteRule ^([.*])/$ index.php?login=$1
            this will rewrite all pages that go like

            to


            does that help?
            Last edited by harshmaul; Feb 12 '08, 12:29 PM. Reason: missed out code tags oops

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Originally posted by jtmphp
              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.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by ak1dnar
                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.

                Comment

                • jtmphp
                  New Member
                  • Feb 2008
                  • 9

                  #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.

                  Comment

                  • harshmaul
                    Recognized Expert Contributor
                    • Jul 2007
                    • 490

                    #10
                    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.

                    Comment

                    • ifedi
                      New Member
                      • Jan 2008
                      • 60

                      #11
                      Originally posted by harshmaul
                      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....

                      Code:
                      RewriteEngine on
                      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.

                      Comment

                      • jtmphp
                        New Member
                        • Feb 2008
                        • 9

                        #12
                        Thanks all for your replies. I am going to try the rewrite.

                        Comment

                        Working...