Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thoughts on PHP parsing of URL 1

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
I need to create a PHP script to parse out the URL/Querystring.

I will use the info to redirect the request through my own template file but there are a few things I need to consider.

The URL may be a full URL like or it may be a relative path like myfile.htm or /subfolder/myfile.htm, so I have to look for both possibilities.

The URL may contain parameters like myfile.htm?someval=12&anotherval=Test
Or it may be like myfile.htm#something.
I want to preserve these so they can be passed on to the content page that will be loaded.
Are there other things on the URL I should be looking for as well? I do not want to block capabilities the pages would have if their links were loading the pages directly rather than going through my script.
Can a URL contain both ?myval=something and #something and if so is there a requirment for the order in which they appear?

I am using header("Location:......") to redirect the page with the newly modified URL. If the original link is to a page outside of the local web site I would like that page to open in a new window rather than altering the current browsers path. Can this be done from PHP or do I need client-side code for it?

Any thoughts on other things I may need to look for when processing the URL for the redirection?

I have been looking around at bits of code for parsing and none so far seem to accomodate whole and relative paths or cover all of the possible parameters I may have to look for so I may have to go from scratch. Any suggestions on approach or which methods would be particularly useful would be appreciated as I am unfamiliar with most PHP methods and functions.

Thanks.

It's hard to think outside the box when I'm trapped in a cubicle.
 
It never returns any of the string from the # on so I have nothing to work with parsing it out.

It looks as if fragments on the URL are never truly passed to the server. I can parse out a URL that I generate in code and return the fragment but I have never been able to pull the fragment from the requested URL.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top