phphttp-redirectbit.ly

How to get redirecting url link with php from bit.ly


I'm trying to get url links to those bit.ly redirects. I've tried to open bit.ly links with file_get_contents but it already gets content from redirected site, but how to get its url?


Solution

  • I was unaware of the bit.ly API, here is the raw way to do it:

    $context = array
    (
        'http' => array
        (
            'method' => 'GET',
            'max_redirects' => 1,
        ),
    );
    
    @file_get_contents('http://bit.ly/cmUTtb', null, stream_context_create($context));
    
    echo 'Redirect to: ' . str_replace('Location: ', '', $http_response_header[6]);