cURL, get link behind redirect tutorial

Mutikasa

Power Member
Joined
May 23, 2011
Messages
589
Reaction score
216
If you have link1 that redirects to link2, but you need to get link2, this is the code
PHP:
function get_link2($link1) {
$ch = curl_init($link1);

curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

$header = "Location: ";
$pos = strpos($response, $header);
$pos += strlen($header);
$link2 = substr($response, $pos, strpos($response, "\r\n", $pos)-$pos);
return $link2; }
 
Back
Top