Forum Moderators: coopster

Message Too Old, No Replies

How to read a URL with a script

         

erikcw

4:04 am on Sep 22, 2004 (gmt 0)

10+ Year Member



I am trying to echo a different html title based on the URL of the site. The problem is, I can't seem to figure out how to read the URL. Is there a way to read either the full URL or just the filename (ie article.php, links.php, etc....). Perhaps a server variable?

I have found a couple of functions at php.net which will parse URL data into parts, but how do I get the URL (or path, but URL would be more useful in my case since multiple domains are used) into the function at run time?

I will take that information and then use it to query MySQL or an array to echo data into the title tags of my pages....

Any ideas?

Thanks!
Erik

IanKelley

5:13 am on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Take a look at the following environment variables:

REQUEST_URI, SCRIPT_FILENAME and SCRIPT_NAME

erikcw

8:12 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Worked like a charm! Thanks

erikcw

2:12 am on Sep 23, 2004 (gmt 0)

10+ Year Member



I think I have a problem now. Check this out. When I type in www.domain-b.com I get the data for www.domain-a.com, but if I go to another page, (ie links.php), everything works correctly. I use php includes for the site temaplate, so everything should be the same


if ($_SERVER['HTTP_HOST'] == "www.domain-b.com" OR $_SERVER['HTTP_HOST'] == "domain-b.com") {
$site_mirror = "mmi";
} else {
$site_mirror = "mms";
}

<? if ($site_mirror == "mmi") { echo "mmi/logommi.gif"; } else { echo "logo.gif"; }?>

Any idea why this may be happening? I am usting ServerAlias in httpd.conf to make both domains point to the same content...

IanKelley

2:33 am on Sep 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A lot of times SERVER_NAME environment variable is more reliable than HTTP_HOST, try that instead.

coopster

10:18 am on Sep 23, 2004 (gmt 0)