Forum Moderators: coopster

Message Too Old, No Replies

Getting Header Response Codes

Testing on Localhost but just can't seem to get the code

         

neophyte

1:31 am on Jul 26, 2010 (gmt 0)

10+ Year Member



Hello All -

I'm writing a script that ***should be*** sending back the status code for the URL requested.

I'm doing this on my local box as a development test with the following script:

function get_status_code($url) {
$headers = get_headers($url);
return substr($headers[0], 9, 3);
}

$url = 'http://localhost/sangat_test/index.php';

echo get_status_code($url);

But when I try this nothing happens - page just tries to load and load and load.

Any idea what I'm doing wrong? Is it not possible to get/test header information from localhost?

Any guidance greatly appreciated.

Neophyte

penders

6:52 pm on Jul 26, 2010 (gmt 0)

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



As long as the domain resolves on your machine (which it should - hey, it must be!) this should be OK? But you'll get a Warning if it didn't. And... providing the page you're testing this on isn't "http://localhost/sangat_test/index.php" - infinite loop!