capture redirected URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarapb
    New Member
    • Sep 2011
    • 1

    capture redirected URL

    How to capture the final url that a website redirects to ?
    For example: http://www.facebook.com/#!/pages/Gra...15114445194693

    redirects to http://www.facebook.com/pages/Gran-P...15114445194693

    Using below code:
    I am getting the same link not the final link.

    Code:
    <?php
    
    $thisurl = "http://www.facebook.com/#!/pages/Gran-Piatto-dOro-Restaurant-New-York-NY/215114445194693";
    $options = array(
     CURLOPT_RETURNTRANSFER => true,    
     CURLOPT_HEADER         => true,    
     CURLOPT_FOLLOWLOCATION => true,     
     CURLOPT_ENCODING       => "",       
     CURLOPT_USERAGENT      => "spider", 
     CURLOPT_AUTOREFERER    => true, 
     CURLOPT_CONNECTTIMEOUT => 120, 
     CURLOPT_TIMEOUT        => 120,
     CURLOPT_MAXREDIRS      => 10 );
    
    $ch = curl_init( $thisurl );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch ); 
    
    echo $header["url"];
    
    ?>
    What I am missing here ? Any response is appreciated, Thanks
    Last edited by Dormilich; Sep 16 '11, 06:43 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a hash (#) in an URL denotes an anchor, so there is no guarantee that you can get that value in PHP*. with JavaScript that is a different topic …


    a simple test with phpinfo() yielded no result

    Comment

    Working...