note 117256 added to function.get-headers
| From: | bobray at softville dot com | Date: | Mon, 11 May 2015 05:29:02 +0000 |
| Subject: | note 117256 added to function.get-headers | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202492@lists.php.net to get a copy of this message | ||
Testing the validity of a URL that is preceded by one or more server redirects is tricky. There will
be more than one status code returned and all but the first will be redirect codes.
This function will return an integer containing the three digit status code of the last code
returned, which is what you want.
function getStatus($url) {
$headers = @get_headers($url, true);
foreach($headers as $k => $v) {
if (! is_int($k)) continue;
$value = $v;
}
return (int) substr($value, strpos($value,' ', 8) +1, 3);
}
----
Server IP: 72.52.91.14
Probable Submitter: 70.197.195.4
----
Manual Page -- http://php.net/manual/en/function.get-headers.php
Edit -- https://master.php.net/note/edit/117256
Del: integrated -- https://master.php.net/note/delete/117256/integrated
Del: useless -- https://master.php.net/note/delete/117256/useless
Del: bad code -- https://master.php.net/note/delete/117256/bad+code
Del: spam -- https://master.php.net/note/delete/117256/spam
Del: non-english -- https://master.php.net/note/delete/117256/non-english
Del: in docs -- https://master.php.net/note/delete/117256/in+docs
Del: other reasons-- https://master.php.net/note/delete/117256
Reject -- https://master.php.net/note/reject/117256
Search -- https://master.php.net/manage/user-notes.php