Jump to content

[cURL] Detect if there is a header(); on a page


YBthebest

Recommended Posts

Hey all!

 

Well the title is quit clear! I wanted to know how I can, through PHP, detect on a webpage if it uses the header() function to redirect to another page, in php! ( something like this : header('Location h31uh23i.php');  )

 

I think I need to use cURL for this!

 

Thank you very much if you can help me!

Link to comment
Share on other sites

Well you say it won't work but that is really weird...I've got a script that checks if there is some changement in a page, by checking if there is a <form on the page or if an image is still there ( the two methods work ) but they don't work when the page changes....and what they do, they add a header redirection on the first page and then it redirects to the second page, the important page. So my script doesn't detect any change it the page...

 

And when I enter the URL of the second page, it detects the change...

 

I'm lost!

 

Did you understand anything xD?

Link to comment
Share on other sites

//detect header redirects
$uri      = 'http://google.com';
$headers  = get_headers($uri, 1);

$redirect = $headers['Location'];
unset($headers);
if ( count($redirect) > 1 )
{
   // redirects occured
}
//redirects stored like so: $redirect[0] = 'http://google.com'; $redirect[1] = 'http://google.co.uk'; // etc..

 

If you wish to use curl on each redirect that took place:

 

<?php

$uri      = 'http://google.com';
$headers  = get_headers($uri, 1);

$redirect = $headers['Location'];
unset($headers);
$i = 0;
   foreach($redirect as $redirect)
   {
       $ch[$i] = curl_init();
       curl_setopt($ch[$i], CURLOPT_URL, $redirect);
       //etc...
       ++$i;
    }

    $mh = curl_multi_init();
    foreach($ch as $cm)
    {
        curl_multi_add_handle($mh, $cm);
    }

    curl_multi_exec($mh);
    
    foreach($ch as $cm)
    {
        curl_multi_remove_handle($mh, $cm);
    }
    
    curl_multi_close($mh);
?>

 

This will be very resource intensive...

Link to comment
Share on other sites

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.