YBthebest Posted November 1, 2010 Share Posted November 1, 2010 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! Quote Link to comment Share on other sites More sharing options...
micah1701 Posted November 1, 2010 Share Posted November 1, 2010 yeah, no, it won't work. cURL just reads the page as a browser would view it. Quote Link to comment Share on other sites More sharing options...
sastro Posted November 1, 2010 Share Posted November 1, 2010 <?php $url = 'http://www.example.com'; print_r(get_headers($url)); print_r(get_headers($url, 1)); ?> Quote Link to comment Share on other sites More sharing options...
YBthebest Posted November 3, 2010 Author Share Posted November 3, 2010 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? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 3, 2010 Share Posted November 3, 2010 //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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.