Created
January 11, 2010 00:01
-
-
Save shupp/273875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cookie helper for dealing with Zend Http responses. | |
* | |
* @author Bill Shupp <hostmaster@shupp.org> | |
* @copyright 2010 Bill Shupp | |
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD | |
*/ | |
class MS_Cookie | |
{ | |
/** | |
* Adds a cookie to a response object | |
* | |
* @param Zend_Http_Cookie $cookie The cookie object | |
* @param Zend_Controller_Response_Abstract $response The response object | |
* @param bool $httpOnly HttpOnly bool, true default | |
* | |
* @return void | |
*/ | |
public static function add(Zend_Http_Cookie $cookie, | |
Zend_Controller_Response_Abstract $response, $httpOnly = true) | |
{ | |
$time = $cookie->getExpiryTime(); | |
$string = rawurlencode($cookie->getName()) . '=' . rawurlencode($cookie->getValue()) . ';'; | |
$string .= ' domain=' . $cookie->getDomain() . ';'; | |
if ($time) { | |
$string .= ' expires=' . gmdate('D, d-M-Y H:i:s', $time) . ' GMT;'; | |
} | |
$string .= ' path=' . $cookie->getPath() . ';'; | |
if ($cookie->isSecure) { | |
$string .= ' secure;'; | |
} | |
if ($httpOnly) { | |
$string .= ' HttpOnly;'; | |
} | |
$response->setHeader('Set-Cookie', $string); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment