Simple URL Parser

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
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Simple URL Parser

Post by LanceEh »

Ok, I was running into a problem with a URL in a dynamic site because the links were registering wrong when trying $_SERVER['PHP_SELF'] $_SERVER['REQUEST_URI'] and $_SERVER['SCRIPT_NAME'] due to Mod_Rewrite, so I had to manually strip the URL using.

$url=parse_url($_SERVER['PHP_SELF'],PHP_URL_QUERY);

Which has worked so far.

P.S. ['PHP_SELF'] worked until a variable was appended to the end, then it kept adding variables, (rather than the URL without the variables). Oh well, it works now unless someone else has a better solution.

Take care.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Simple URL Parser

Post by pickle »

Don't use PHP_SELF - it's not guaranteed to be set. Use REQUEST_URI instead.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Re: Simple URL Parser

Post by LanceEh »

ok, thanks. Don't think that code was working anyway.
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

Re: Simple URL Parser

Post by semlar »

Maybe this could be fixed by adjusting your rewriterule.
Post Reply