Checking URL Segments?

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
Vik
Forum Newbie
Posts: 13
Joined: Sun May 23, 2004 1:12 pm
Location: Los Angeles, CA

Checking URL Segments?

Post by Vik »

I've got a weblog that uses the ExpressionEngine blogging CMS, which is written in PHP.

I'm trying to get one of my templates to include some PHP code that will check the URL segments of the URL that loaded it.

In a post on the EE forums, I got this advice:
You could check the URL segments. If there's an entry ID or "URL Title" then you know it's from a permalink.
What's the correct way to do this in PHP? Thanks very much in advance for any info.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You can get the $_SERVER['HTTP_REFERER'] which should hopefully have the full url of the page the user came from and then you know that any var sent to that page would have to be after a '?', so you can explode the string and your left with the page location and the variables set to that page, then if theres more than 1 variable sent to the page they are seperated by '&', so explode by that again.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Also, look at [php_man]parse_url[/php_man]
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply