Page 1 of 1
check the current domain...
Posted: Tue May 11, 2004 6:09 am
by batfastad
Here's what I want to do...
I have two domain names, domain1.com and domain2.com both pointing to the same webspace.
How do I detect which one the user is using?
Basically I to do an if domain = domain1.com then do one load of PHP stuff, else do some different PHP stuff.
I'm just having trouble getting the domain name from the headers - not really sure how that works.
I know it's really easy, but I'm just starting out in PHP and i'm having trouble with the basic syntax.
Thanks
Batfastad
Posted: Tue May 11, 2004 6:16 am
by magicrobotmonkey
Code: Select all
<?php
echo $_SERVER['HTTP_REFERER'];
?>
Give that a whirl...
Posted: Tue May 11, 2004 7:15 am
by batfastad
For some reason that doesn't work - printing the referer on the page!
Here's my code, the includes work but the echo command doesn't - am I doing something stupid?
[syntax=php]<?php
include "apsheader.php";
?>
<br />
<br />
<h1>TEST</h1>
<br /><br />
<?php
echo $_SERVER['HTTP_REFERER'];
?>
<?php
include "apsfooter.php";
?>[/syntax]
I know there is no need to escape from PHP after the echo command, but I just copy and pasted from my code to add some HTML in there in a minute.
Any reason why the echo $_SERVER isn't working?
Thanks
Batfastad
Posted: Tue May 11, 2004 7:18 am
by magicrobotmonkey
try
Code: Select all
<?php
echo "<pre>";
print_r($_SERVER);
echo"</pre>";
?>
and post results here...
are you simply looking at this page yourself? If you are just typing the address in, I believe referrer will be empty...
Posted: Tue May 11, 2004 7:38 am
by batfastad
Oh yeah, I was just typing the address in.
Of course, because noone is referring me to that page, it will be empty
Here are the results...
[C_DOCUMENT_ROOT] => /files/home1/dealerworld/
[DOCUMENT_ROOT] => /usr/local/www/data
[HTTP_ACCEPT] => */*
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-gb
[HTTP_CONNECTION] => Keep-Alive
[HTTP_HOST] =>
http://www.amdproshow.com
[HTTP_IF_MODIFIED_SINCE] => Fri, 12 Mar 2004 12:21:21 GMT; length=709
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
[MYU] =>
http://www.amdproshow.com
[PATH] => /sbin:/bin:/usr/sbin:/usr/bin
[REDIRECT_C_DOCUMENT_ROOT] => /files/home1/dealerworld/
[REDIRECT_DOCUMENT_ROOT] => /files/home1/dealerworld/
[REDIRECT_MYU] =>
http://www.amdproshow.com
[REDIRECT_SCRIPT_URI] =>
http://www.amdproshow.com/
[REDIRECT_SCRIPT_URL] => /
[REDIRECT_SERVER_ADMIN] => postmaster@.plus.com
[REDIRECT_SERVER_NAME] => cgi..plus.com
[REDIRECT_STATUS] => 200
[REDIRECT_UNIQUE_ID] => QKDI0sOmgngAAAXqUqU
[REDIRECT_URL] => /
[REMOTE_ADDR] => 81.174.131.4
[REMOTE_PORT] => 11082
[SCRIPT_FILENAME] => /files/home1/dealerworld/index.php
[SCRIPT_URI] =>
http://www.amdproshow.com/
[SCRIPT_URL] => /
[SERVER_ADDR] => 195.166.130.120
[SERVER_ADMIN] =>
support@plus.net
[SERVER_NAME] =>
http://www.amdproshow.com
[SERVER_PORT] => 80
[SERVER_SIGNATURE] =>
Posted: Tue May 11, 2004 7:42 am
by batfastad
There is no HTTP_REFERER listed above thus meaning it must be blank - correct?
Is there another way to do this?
Thanks
Posted: Tue May 11, 2004 7:43 am
by batfastad
Ahh, I guess I can use HTTP_HOST ??
Is HTTP_HOST the one I need?
I can easily set something up like the following...
If HTTP_HOST = amdproshow.com
include amdproshow pages
else
include domain2.com pages
Thanks!
Posted: Tue May 11, 2004 7:54 am
by magicrobotmonkey
oh yea that might work - also SCRIPT_URI perhaps - you can parse it to get just the domain. I misuderstood your original post is why I said referrer, sorry!
Posted: Tue May 11, 2004 8:10 am
by batfastad
Thanks for the help - it got me in the right direction.
And now I know how to use the predefined variable arrays! Something I've been battling with for a while.
Thanks again