current URL?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rockindie
Forum Newbie
Posts: 7
Joined: Sun May 23, 2004 3:32 pm

current URL?

Post by rockindie »

is there any PHP code i could use to find out what is the exact url that the user has reached the site by.
like return respectively "http://mysite.com/blah.php". i hope i have explained myself well. thanks in advance.

(i'd like to use this to have 2 domains parked on one webhost, like site1.com and site2.com have the same webhost/files but the code would figure out if youve visited the site by going to site1.com or site2.com so it would display the correct site)
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

$_SERVER['HTTP_REFERER']

I think thats the right one.
rockindie
Forum Newbie
Posts: 7
Joined: Sun May 23, 2004 3:32 pm

Post by rockindie »

Steveo31 wrote:$_SERVER['HTTP_REFERER']

I think thats the right one.
nope, doesnt seem like it, i believe that will return like "google.com" if the user went to google.com then went to my site
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$_SERVER['HTTP_HOST']; with
$_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'];

If you do a var_dump($_SERVER); you'll see the elements you can use to build up the current, full, url.
rockindie
Forum Newbie
Posts: 7
Joined: Sun May 23, 2004 3:32 pm

Post by rockindie »

markl999 wrote:$_SERVER['HTTP_HOST']; with
$_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'];

If you do a var_dump($_SERVER); you'll see the elements you can use to build up the current, full, url.
thanks, i found it just as you posted it to in the manual. has anyone else used a method like this to host 2 domains on one webserver
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

has anyone else used a method like this to host 2 domains on one webserver
I use on sites such as dev.foo.com, beta.foo.com, alpha.foo.com etc.
I use :
define ('SITE', substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.')));

And SITE will be either dev, beta, alpha etc.. then i use that to get site specific configuration vars.
Post Reply