[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…

Thanks!

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

[php]

<?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; } ?>

[/php]

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…

Thanks!

Try this for curl:

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

$data = curl_getinfo($c);
curl_close($c);
$header = substr($response, 0, $data[‘header_size’]);
?>[/php]

Wow Thank you very much !

http://ybthebest.com/test/

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 ?

Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service