SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Aug 16, 2007, 13:47 #1
- Join Date
- Mar 2004
- Location
- Orlando, FL
- Posts
- 151
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Is there a way to find out what a url redirects to in PHP?
Every day on my blog, I have a list of about 30 other blogs that I link to. Lately, more and more of then have been using feedburner, which means that the links to their posts show up like this:
http://feeds.feedburner.com/~r/Jorda.../~3/144521539/
Is there a function in php that will find out what that URL redirects to, and return the actual URL of the post instead of the feedburner URL?
-
Aug 16, 2007, 18:17 #2
You can use fsockopen to send a request and read the response, which will give you code 3xx and the link to the redirected page.
If you're using php5, get_headers makes things a little bit easier:
Code php:$headers=get_headers($url, 1); if(isset($headers['Location'])){ $location=$headers['Location']; }else{ $location=$url; }
Saul
-
Aug 17, 2007, 12:30 #3
- Join Date
- Mar 2004
- Location
- Orlando, FL
- Posts
- 151
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm still using php 4... is there an equivalent to "get_headers" in php 4?
-
Aug 17, 2007, 12:34 #4
Nope. Your best call is using fsockopen and parsing headers manually. Check out the page on php manual, there are examples.
Luckily, though, a quick search on phpclasses.org gave me this class http://www.phpclasses.org/browse/package/917.html
Give it a go.Saul
Bookmarks