Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

redirect - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...