Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect URL used to access site. 1

Status
Not open for further replies.

BiggerBrother

Technical User
Sep 9, 2003
702
GB
Is there anyway to find the domain name used to access my site? I have a site, with multiply domain names pointing to the same site. Is there anyway to find out which name the user has entered to get to the site?

Basically, I need to return the nae into a php script, so that the site can have a different css file applied for each domain.

Many thanks

BB
 
Unfortunately, both of these options return the actual site address.

Thanks for the quick reply though

BB
 
Then I don't understand what you want.

On my machine, $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] return the fully-qualified domain name of the server to which I connected.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I have a site, which i access through: This is the site name which is registered to this server.

I have a second domain name: which i point to the main site.

However, one site is used for one form of advertising, and the other is promoted through other means. What I need is to identify which site is bringing in the traffic, and then using php, colour the site differently, depending on the domain accessed.

SERVER_NAME and HTTP_HOST return the somain name which is registered to the server in both instances, rather than the domain name entered.

Many thanks

BB
 
Do you mean, you want the site from which the user came to your script? That's in $_SERVER, too. Try $_SERVER['HTTP_REFERER'].

Keep in mind, though, that this information will exist if and only if the user's web browser reports it. Many web browsers do not report this information.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
THis method doesn't work, as they don't actually come from another site, the DNS just forwards them to this site automatically.

There must be another way, I just can't see the wood for the trees.

BB
 
I simply don't understand what it is you want.

On my server, I have a script show_server.php, which reads:

Code:
<?php
print '<html><body><pre>';

print_r ($_SERVER);

print '</pre></body></html>';

?>

That server, an Apache machine, has a virtual server with the servername "linuxdev.<something>.local" on it, which resolves to an private IP address. If I point my web browser to [ignore][/ignore], then $_SERVER['SERVER_NAME'] contains "linuxdev.<something>.local".

When I edit my workstation's hosts file so that foo.local also resolves to the same IP address as my server and point my web browser to [ignore][/ignore], then $_SERVER['SERVER_NAME'] contains "foo.local". This is even though "foo.local" is not a configured name on my Apache server.

Isn't this what you want?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
That is exactly what I want, but it doesn't reutn the value. At the moment, i have a page, with :

echo $_SERVER['SERVER_NAME'];

The site is hosted at: and the returned string is mysite.COM, when I use this as the web address. mysite.CO.UK also points to the same site, using web forwarding, set up with 123-reg.co.uk, and when it gets to this page, returns mysite.COM.

Why is this?

How can I work around it?

BB
 
What, exactly, is the configuration for the "web forwarding" of mysite.co.uk? When I've done this, I've entered mysite.com as the forwarded address for mysite.co.uk.

This is usually done via frames. Your server never sees the request to mysite.co.uk; only the forwarding server sees that.

Set up mysite.co.uk in DNS to point to the same address as mysite.com and run 2 virtual servers. Then you should get what you want.
 
BiggerBrother:
Have you done as I have, connecting to that site by using a different name but the same IP address by editing your hosts file?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Updating at the monent. Have set an alias on the server, so hopefully, that will fix the problem of web-forwarding.

Many thanks. I'll let you know how i get on.

BB
 
Perfect. Setup an alias on the same domain, and it now works perfectly. Using server_name to find the domain name used to access the pages, and then setting global variables accordingly.

Thanks for all your help.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top