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

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!

Yes, you can use cURL, or some of existing classes like Snoopy - this is cool and easy to use tool.

I am Yannick, just created an account !

Well thank you! But do you know how we can do it with cURL or Snoppy? Because I really don’t know both of them so…


If you downloaded and un-zipped snoopy class, here is how you can use it to retrieve http headers:


<?php include("Snoopy.class.php"); $sn = new Snoopy; if($sn->fetch("http://www.mysite.com/mypage.html")){ if(is_array($sn->headers)){ echo implode("
",$sn->headers); } } else{ echo 'Error: '.$sn->error; } ?>


There are dosen of options in Snoopy script that you can try for your task ($maxredirs, $lastredirectaddr, etc. - see Snoopy’s docs)

Thank you very much for this code!

I wanted to know, do you know how to do this in cURL too ? If you don’t I’ll just take this one, but I would like to see how this is done with cURL…


Try this for curl:

$c = curl_init(‘http://www.mysite.com/mypage.html’);
curl_setopt($c, CURLOPT_HEADER, 1);
$r = curl_exec($c);

$data = curl_getinfo($c);
$header = substr($response, 0, $data[‘header_size’]);

Wow Thank you very much !


But this is what I get ! Why does it try to show the images of the page? ( splash, Lockerz PTZ Place Redemption Site )?

And it shows all the headers, is it possible to show only the redirection header ?


Sponsor our Newsletter | Privacy Policy | Terms of Service