note 117528 added to reserved.variables.server
| From: | doublecompile at gmail dot com | Date: | Wed, 24 Jun 2015 20:32:54 +0000 |
| Subject: | note 117528 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202942@lists.php.net to get a copy of this message | ||
I've used the SplPriorityQueue to determine an HTTP client's preferred MIME types that are
in $_SERVER['HTTP_ACCEPT'].
<?php
$queue = new \SplPriorityQueue();
foreach (preg_split('#,\s*#', $_SERVER['HTTP_ACCEPT']) as $accept) {
$split = preg_split('#;\s*q=#', $accept, 2);
$queue->insert($split[0], isset($split[1]) ? (float)$split[1] : 1.0);
}
foreach ($queue as $mime) {
echo $mime, PHP_EOL;
}
?>
My browser sends:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
And this script outputs:
text/html
application/xhtml+xml
application/xml
*/*
A better example:
Accept: text/html, application/xml,text/css;q=0.4,text/plain; q=0.9, application/json;q=0.8
And this script outputs:
text/html
application/xml
text/plain
application/json
text/css
----
Server IP: 72.52.91.14
Probable Submitter: 108.3.219.161
----
Manual Page -- http://php.net/manual/en/reserved.variables.server.php
Edit -- https://master.php.net/note/edit/117528
Del: integrated -- https://master.php.net/note/delete/117528/integrated
Del: useless -- https://master.php.net/note/delete/117528/useless
Del: bad code -- https://master.php.net/note/delete/117528/bad+code
Del: spam -- https://master.php.net/note/delete/117528/spam
Del: non-english -- https://master.php.net/note/delete/117528/non-english
Del: in docs -- https://master.php.net/note/delete/117528/in+docs
Del: other reasons-- https://master.php.net/note/delete/117528
Reject -- https://master.php.net/note/reject/117528
Search -- https://master.php.net/manage/user-notes.php