Jump to content

URL Question


timmah1

Recommended Posts

I have a photo hosting site, and when the user signs up, they get their own domain, kinda like myspace

What I want know is, when someone types in the url of a person (ie http://www.domainname.com/user), how would PHP know to pull information associated with that user?
Link to comment
Share on other sites

well all you need is to get the domain name from a http request, and match that with the database information. Lets says johnnysdomain is in the url requested of your host, you look that up in the database where you inputted the domain name originally.

If you notice:

[code]
$host_name = explode (".", $_SERVER['HTTP_HOST']); // quite lazy
[/code]
$host_name[0] or $host_name[1] will get you the domain name and you just have to match that to the database (key 0 may be www, ftp, etc.)
Link to comment
Share on other sites

you need a .htaccess file
and in it you would place something like this:
[code]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)/$ /user_page.php?username=$1
[/code]

Then in your PHP file just search the database something like this:
[code]
<?php
    $sql = mysql_query("select * FROM users where username='{$_GET['username']}' LIMIT 1");
    while($row = mysql_fetch_array($sql)){
          echo$row['username'];
          echo$row['userid'];
          echo$row['filename'];
    }
?>
[/code]
That is just an example of how to do it, but the .htaccess file is required, and for an .htaccess tutorial, go here: http://corz.org/serv/tricks/htaccess2.php -- its one I really like.
Link to comment
Share on other sites

ok, i'm a dumb ass.

I didn't mean to say their own 'domain', the get their own 'directory', which is a alot different

http://www.domainname.com/directory

How would I pull the username from just typing in the address the url?
The username will always be the directory, in this example, the username is 'directory'

I'm trying to understand this, but for some reason it's not sticking
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.