Change Content on Page Depending on 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
andynaylor
Forum Newbie
Posts: 2
Joined: Thu Jan 14, 2010 4:16 pm

Change Content on Page Depending on URL

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Change Content on Page Depending on URL

Post 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.
andynaylor
Forum Newbie
Posts: 2
Joined: Thu Jan 14, 2010 4:16 pm

Re: Change Content on Page Depending on URL

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Change Content on Page Depending on URL

Post 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.
Post Reply