note 110455 deleted from function.http-parse-cookie by danbrown

From: Date: Thu, 06 Dec 2012 14:28:35 +0000
Subject: note 110455 deleted from function.http-parse-cookie by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192338@lists.php.net to get a copy of this message
Note Submitter: coder.ua[at]gmail.com ---- 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; }

« previous php.notes (#192338) next »