Jump to content

Recommended Posts

Hello,

 

Recently, I'm asked to check URLs scripts for a redirect code, to see if the job is done or not by other people.

 

So lets say I have like 100 urls to check.

 

Thing is, how am I supposed to be able to check multiple url, go inside the script and find if there's a redirect code on it? Then I have to echo a list that will tell me if the code is there or not (So I guess I get a Bool value) from it.

 

Do I need Regex for this application? I know that I'll need

While (READ URL)

{

Check for redirect code;

Echo if it exists or not;

};

 

Any help would be amazing to get me into the right direction :)

Thank you again!!!!

Link to comment
https://forums.phpfreaks.com/topic/202829-check-redirect-code-from-multiple-url/
Share on other sites

You have the right idea, but finding the redirect code is a bit of a task.

 

You have to account for meta redirects, javascript redirects and potentially flash redirects. Javascript redirects can be on the main page or in a js file. So you would have to read those js files as well and parse them out. Even so a js redirect can be "encoded" and you would have to decode that set of strings to see if it does redirect and just because there is a .location directive does not necessarily mean that the current page is being redirected.

 

So yea, just giving you a heads up to that part (as I have done this before). Regex would work for most of the tests so you may want to look into preg_match but you need to know if you need all redirects or just certain ones as it can get very complicated pretty quick.

Hello, yes I decided to use curl, and from that, I wanted to search for an ID number to see if the site is redirected to the right place.

 

sadly, it seems the my code is unable to retrieve the content of the site that it's redirected to...actually, it can't even get any site content at all. Here's my code.

 

 

 

fclose($file_open);

                       

                 

foreach ($site_array as $site)

{                       

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $site);                                                   

    $site_content = curl_exec($curl);

 

echo $site;

echo $sitecontent;

 

 

 

  // $site_content = file_get_contents($site);               

                           

    if (strpos($site_content, $redirectId) != false)

        echo $site . "," . "true" . "<br />" ;

    else

        echo $site . "," . "false" . "<br />" ;

 

}         

Solved my own problem....but the thing is that now sometimes the script gives the right vlaue, and sometimes it does not...wtf? Please can someone tell me

if this is code that is wrong?

 

 

 

                       

           

foreach ($site_array as $redirectId => $site)

{   

                 

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, $site); 

curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);

    $site_content = curl_exec($curl);

curl_close($curl);

 

echo strpos(htmlentities($site_content), $redirectId) . ",    ";

echo $redirectId;

 

/*

  $site_content = file_get_contents($site);               

  preg_match('/$redirectId/', $site_content, $matches);

  print_r ($matches);

*/

 

    if (strpos(htmlentities($site_content), $redirectId) != 0)

        echo $site . ", " . "true" . "<br />" ;

    else

        echo $site . ", " . "false" . "<br />" ;

 

}   

 

fclose($file_open);                 

?>

 

Sometimes, the script is unable to search through the website :(

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.