Forum Moderators: coopster

Message Too Old, No Replies

checking server HTTP header

for any page

         

WebRankInfo

3:15 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



I wrote a code that checks the server HTTP header but it only works with the root.

For example, it works for: -http://www.example.com/
and it doesn't work for: -http://www.example.com/test/

I open a connection to -http://www.example.com/ with fsockopen() and then I use:
@fputs($fp, "HEAD ".$url_path." HTTP/1.0\r\n");

where $url_path is either '/' or '/test/' for my 2 examples.
What's the problem?

GeorgeGG

6:43 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



I do this, but not in PHP.

" HTTP/1.0\r\n"
Is the '\r\n' the same as 2 linefeeds?

In my code I use:
" HTTP/1.0\n\n"
2 linefeeds.

GGG

WebRankInfo

7:02 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



2 line feeds doesn't change anything for me :-(

this works well:
@fputs($fp, "HEAD / HTTP/1.0\r\n");

but this:
@fputs($fp, "HEAD /test/ HTTP/1.0\r\n");
returns a 404 status code whereas this directory exists.

GeorgeGG

7:23 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



Found this example at php net

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "HEAD /test/ HTTP/1.0\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";

fputs($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
?>

Seems to work on my site.

GGG

WebRankInfo

8:01 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



Thank you GeorgeGG, it works fine!

ergophobe

10:10 pm on Jan 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Is the '\r\n' the same as 2 linefeeds?

\r = carriage return
\n = line feed

\r\n - Windows new line
\r - Mac new line
\n - *nix new line.

So what you have there would normally be a Windows line break (just one), but I don't know in this case.

GeorgeGG

10:27 pm on Jan 4, 2004 (gmt 0)

10+ Year Member



I don't use PHP and could not remember what the \r
was for but knew we needed to end with 2 linefeeds:)

So this is the ending line with the 2 linefeeds.
$out .= "Connection: Close\r\n\r\n";

I really need to get some docs on PHP and play with it.

GGG