I have a link which I want to check if it is redirecting to the correct page or not, and if not then I have to display an error message. For example, if my link is
http://www.example.com/redirect.php?x=something
then I will display the error message only when it is redirected to the following link:
http://www.example3.com/
otherwise it's okay and there's no need to display the error message. My script looks like:
$url=urldecode($_GET['l']);
$handle=curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER,TRUE);
$response=curl_exec($handle);
$httpCode=curl_getinfo($handle,CURLINFO_HTTP_CODE);
if(($httpCode==301)||($httpCode==302))
echo 1;
curl_close($handle);
This code just tells whether the URL is redirected or not and does not tell where the URL is being redirected.