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