SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    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?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Zealot
    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?

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •