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

前端 未结 4 1901
难免孤独
难免孤独 2020-12-21 05:11

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

4条回答
  •  误落风尘
    2020-12-21 05:12

    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]);
    

提交回复
热议问题