tags:

views:

149

answers:

1

I'm looking for the most effecient way to resolve a given url to its final end point, following all 30x redirects and location headers.

Basically, I have a bunch of URLs like http://foo.com that when you go to them, they end up at a page like http://foo.com/Welcome.html and i need to find that last url.

right now, i'm using CURLOPT_FOLLOWLOCATION and CURLOPT_NOBODY (since i really dont care about the text returned) and once its exec'd, i run curl_getinfo() and save the 'url' key from that array.

i just keep thinking that this is such a huge waste of <something> and there is likely a better way.

EDIT: For those that read this later. I did end up finding a better solution (that didnt involve curl), see get_headers() in php5+

+2  A: 

You can do this manually in php by analysing received headers, but cURL does exactly the same thing. There are no other direct methods, and cURL is the most comfortable one. Don't care about it.

OR you can use some search engines information, that had been already retrived by crawler.

Anton