note 110455 added to function.http-parse-cookie
| From: | coder.ua | Date: | Tue, 23 Oct 2012 23:45:59 +0000 |
| Subject: | note 110455 added to function.http-parse-cookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191508@lists.php.net to get a copy of this message | ||
Some fixes for previos example:
/**
* Get cookies from http-header
* @param string $header
* @return mixed array|bool
*/
public function parseCookies($header)
{
$cookies = array();
$header = explode("\n", $header);
if ( !empty($header) ) {
foreach( $header as $line ) {
if ( preg_match( '/^Set-Cookie: /i', $line ) ) {
$line = preg_replace('/^Set-Cookie: /i', '', trim( $line ));
$csplit = ( strpos($line, ';') !== false ) ? explode(';', $line) :
array($line);
$cdata = array();
foreach($csplit as $data) {
$cinfo = explode('=', $data);
$cinfo[0] = trim($cinfo[0]);
if ( $cinfo[0] == 'expires' || $cinfo[0] == 'Expires' ) $cinfo[1] =
strtotime( $cinfo[1] );
if ( $cinfo[0] == 'secure' || $cinfo[0] == 'Secure' ) $cinfo[1] = true;
if ( in_array($cinfo[0], array('domain', 'expires', 'path',
'secure', 'comment',
'DOMAIN', 'EXPIRES', 'PATH',
'SECURE', 'COMMENT',
'Domain', 'Expires', 'Path',
'Secure', 'Comment' )))
{
$cdata[trim( $cinfo[0] )] = $cinfo[1];
}
else {
$cdata['key'] = $cinfo[0];
$cdata['value'] = $cinfo[1];
}
}
$cookies[] = $cdata;
}
}
}
return $cookies;
}
----
Server IP: 89.251.21.32
Probable Submitter: 89.251.21.33 (proxied: 91.124.129.31)
----
Manual Page -- http://www.php.net/manual/en/function.http-parse-cookie.php
Edit -- https://master.php.net/note/edit/110455
Del: integrated -- https://master.php.net/note/delete/110455/integrated
Del: useless -- https://master.php.net/note/delete/110455/useless
Del: bad code -- https://master.php.net/note/delete/110455/bad+code
Del: spam -- https://master.php.net/note/delete/110455/spam
Del: non-english -- https://master.php.net/note/delete/110455/non-english
Del: in docs -- https://master.php.net/note/delete/110455/in+docs
Del: other reasons-- https://master.php.net/note/delete/110455
Reject -- https://master.php.net/note/reject/110455
Search -- https://master.php.net/manage/user-notes.php