public function get_redirect_url($url){
error_reporting(0);
$header = get_headers($url, 1);
if (strpos($header[0], '301') !== false || strpos($header[0], '302') !== false) {
if(is_array($header['Location'])) {
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else {
return $url;
}
}
public function get_redirect_url(){
error_reporting(0);
$url = $_GET['url'];
stream_context_set_default([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
]);
$header = get_headers($url, 1);
// var_dump($header);
$result = [];
if($header){
if(strpos($header[0], '301') !== false || strpos($header[0], '302') !== false){
$result['code'] = 302;
$result['redirect_url'] = $header['location'];
}else{
$result['code'] = 200;
}
}else{
$result['code'] = 400;
}
echo json_encode($result, JSON_UNESCAPED_UNICODE);
}