note 120075 added to function.get-headers
| From: | bunny at bunny dot hu | Date: | Sat, 22 Oct 2016 14:26:15 +0000 |
| Subject: | note 120075 added to function.get-headers | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206938@lists.php.net to get a copy of this message | ||
If the URL redirected and the new target is also redirected, we got the Locations in array. Also we
got the HTTP codes in a number indexed values.
Here a PART of the header (not all), how it is look like with this redirection chain ( the id=4 is
the landing page):
/test.php?id=1 -> /test.php?id=2 -> /test.php?id=3 -> /test.php?id=4
array
(
[0] => HTTP/1.1 302 Moved Temporarily
[Location] => Array
(
[0] => /test.php?id=2
[1] => /test.php?id=3
[2] => /test.php?id=4
)
[1] => HTTP/1.1 302 Moved Temporarily
[2] => HTTP/1.1 302 Moved Temporarily
[3] => HTTP/1.1 200 OK
)
In a typical situation we need only the landing page information, so here is a small code to get it:
$result = array();
$header = get_headers($url, 1);
foreach ($header as $key=>$value) {
if (is_array($value)) {
$value = end($value);
}
$result[$key] = $value;
}
----
Server IP: 72.52.91.14
Probable Submitter: 82.131.246.182
----
Manual Page -- http://php.net/manual/en/function.get-headers.php
Edit -- https://master.php.net/note/edit/120075
Del: integrated -- https://master.php.net/note/delete/120075/integrated
Del: useless -- https://master.php.net/note/delete/120075/useless
Del: bad code -- https://master.php.net/note/delete/120075/bad+code
Del: spam -- https://master.php.net/note/delete/120075/spam
Del: non-english -- https://master.php.net/note/delete/120075/non-english
Del: in docs -- https://master.php.net/note/delete/120075/in+docs
Del: other reasons-- https://master.php.net/note/delete/120075
Reject -- https://master.php.net/note/reject/120075
Search -- https://master.php.net/manage/user-notes.php