0

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.

N3R4ZZuRR0
  • 2,400
  • 4
  • 18
  • 32
  • your question is a bit hard to understand... why don't you provide a bit of code, so we can use that code to understand the issue? http://stackoverflow.com/help/mcve –  Dec 03 '16 at 12:30
  • @Hallur edited. – N3R4ZZuRR0 Dec 03 '16 at 12:38
  • Am I correct to assume, that the url is acquired by the get variable l? you could use a simple if statement, or a select case, or in_array, to check if l lives up to a certain condition?? –  Dec 03 '16 at 12:42
  • @Hallur Yes, that assumption is correct but how to check the address where that $url is getting redirected? – N3R4ZZuRR0 Dec 03 '16 at 12:45
  • 1
    oh, I see.. you're trying to check the redirection outside of your own server. Now I understand the question, but I don't know how to answer the question, however, I will do some research, as this is an interesting question indeed. –  Dec 03 '16 at 12:46
  • @Hallur yes, you got that correctly. – N3R4ZZuRR0 Dec 03 '16 at 12:48
  • Read the answers to this question http://stackoverflow.com/questions/427203/how-can-i-determine-if-a-url-redirects-in-php the answer by earino should be taken into account. if javascript redirects, your code may not even see it. –  Dec 03 '16 at 12:49

0 Answers0