Page 1 of 1
HTTP header script review
Posted: Sun Oct 02, 2005 10:41 am
by 127.0.0.1
Code: Select all
$ch = curl_init($_POST['url']);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$header = curl_exec($ch);
curl_close($ch);
$header = explode("\r", $header);
for($a = 0; $a < count($header); $a++)
{
if(ereg(":", $header[$a]) OR eregi("HTTP", $header[$a]))
{
echo $header[$a]."<br>";
}
else
{
break;
}
}
Another little script i coded to get your views on. I feel this could be so much better but i cant find any other way of improving it. Speed and performance wise its fine its just the code doesnt look very nice.
Posted: Sun Oct 02, 2005 10:42 am
by Charles256
in your if and else statement indent the statements:-D
Posted: Sun Oct 02, 2005 11:38 am
by d3ad1ysp0rk
In my opinion, this would look a little better:
Code: Select all
$ch = curl_init($_POST['url']);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$header = curl_exec($ch);
curl_close($ch);
$header = explode("\r", $header);
for($a = 0; $a < count($header); $a++){
if(ereg(":", $header[$a]) OR eregi("HTTP", $header[$a])){
echo $header[$a]."<br>";
}
else {
break;
}
}
Or even
Code: Select all
$ch = curl_init($_POST['url']);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$header = curl_exec($ch);
curl_close($ch);
$header = explode("\r", $header);
for($a = 0; $a < count($header); $a++)
{
if(ereg(":", $header[$a]) OR eregi("HTTP", $header[$a]))
{
echo $header[$a]."<br>";
}
else
{
break;
}
}
depending on personal preference.
Posted: Mon Oct 03, 2005 12:02 am
by pilau
I'd rather ask - "what does it do?"
Posted: Mon Oct 03, 2005 3:47 pm
by 127.0.0.1
Code: Select all
$fp = fopen('http://www.microsoft.com', 'r');
print_r($http_response_header);
I found this way -- much better way.
It returns the http headers for a domain.