Page 1 of 1

Change Content on Page Depending on URL

Posted: Thu Jan 14, 2010 4:23 pm
by andynaylor
Hey,

I'm pretty new to php (used to use coldfusion) and I am wanting to display different content on my website dependent on the URL.

I have for 4 URLs on my site that need to display different content within the page. It's a shopping cart system you see and I only get one 'skin' page for the whole of my site. So for example:

IF the URL is http://www.mysite.com DISPLAY this code ELSE display this code

IF the URL is http://www.mysite.com/page.php DISPLAY this code ELSE display this code

Think you catch my drift. Can this be done using PHP, I know its easily done in Coldfusion but my shopping cart isnt in coldfusion, Doh!

Thanks in advance for any helps,
Andy

Re: Change Content on Page Depending on URL

Posted: Thu Jan 14, 2010 4:52 pm
by requinix
If the URL is /foo.bar, which "ELSE" should it observe?

I don't quite get what you're trying to do...
andynaylor wrote:IF the URL is http://www.mysite.com DISPLAY this code
Also known as having an index.php page.
andynaylor wrote:IF the URL is http://www.mysite.com/page.php DISPLAY this code
Also known as having a page.php page.

Re: Change Content on Page Depending on URL

Posted: Thu Jan 14, 2010 5:00 pm
by andynaylor
Basically:

The shopping cart system we use has 1 skin page for the whole site, so you're stuck with the left and right hand navigation bars throughout the site. Now I want to change the right navigation bar on seperate pages and I thought the only way of doing this would be to use the URL as this is different for every page obviously.

So on http://www.mysite.com I want to display one navigation and on http://www.mysite.com/page.php I want to display another navigation.

So dependent on URL it would display different code.

You get it?

Re: Change Content on Page Depending on URL

Posted: Thu Jan 14, 2010 5:30 pm
by requinix
You can use $_SERVER["SCRIPT_NAME"] to determine which PHP file is running (eg, index.php or page.php).
Or $_SERVER["REQUEST_URI"] if your URLs are a bit more complicated than just PHP pages.

Are you sure the system doesn't let you do anything like this? Surprising.