I am using php and curl to get redirect url, I have got the output, but it shows me an error 302 not found at the last redirect(I have to redirect the url twice), Here is my php code,
<?php
$url = 'http://www.example.com/kdjf/ksdjfk/file';
function getred($url){
$ch = curl_init($url);
curl_exec($ch);
if (!curl_errno($ch)) {
$info = curl_getinfo($ch);
return $info['redirect_url'];
}
curl_close($ch);
}
$dds=getred($url);
echo getred($dds);
?>
$dds gives me next redirection after example.com passed and then I have use the redirect function again, And I have got an error,
<html>
<head>
<title>302 Found</title>
</head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
http://www.example.org/skdfjk/new_file.html
How to get only http://www.example.org/skdfjk/new_file.html
without any error. or html tags.