- return true;
- }
-
- /**
- * Serialize the cookie jar into a format useful for HTTP Request headers.
- * @param $path string the path that will be used. Required.
- * @param $domain string the domain that will be used. Required.
- * @return string
- */
- public function serializeToHttpRequest( $path, $domain ) {
- $ret = "";
-
- if( $this->canServeDomain( $domain )
- && $this->canServePath( $path )
- && $this->isUnExpired() ) {
- $ret = $this->name ."=". $this->value;
- }
-
- return $ret;
- }
-
- protected function canServeDomain( $domain ) {
- if( $domain == $this->domain
- || ( strlen( $domain) > strlen( $this->domain )
- && substr( $this->domain, 0, 1) == "."
- && substr_compare( $domain, $this->domain, -strlen( $this->domain ),
- strlen( $this->domain ), TRUE ) == 0 ) ) {
- return true;
- }
- return false;
- }
-
- protected function canServePath( $path ) {
- if( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 ) {
- return true;
- }
- return false;
- }
-
- protected function isUnExpired() {
- if( $this->isSessionKey || $this->expires > time() ) {
- return true;
- }
- return false;
- }
-
-}
-
-class CookieJar {
- private $cookie = array();
-
- /**
- * Set a cookie in the cookie jar. Make sure only one cookie per-name exists.
- * @see Cookie::set()
- */
- public function setCookie ($name, $value, $attr) {
- /* cookies: case insensitive, so this should work.
- * We'll still send the cookies back in the same case we got them, though.
- */
- $index = strtoupper($name);
- if( isset( $this->cookie[$index] ) ) {
- $this->cookie[$index]->set( $value, $attr );
- } else {
- $this->cookie[$index] = new Cookie( $name, $value, $attr );
- }
- }
-
- /**
- * @see Cookie::serializeToHttpRequest
- */
- public function serializeToHttpRequest( $path, $domain ) {
- $cookies = array();
-
- foreach( $this->cookie as $c ) {
- $serialized = $c->serializeToHttpRequest( $path, $domain );
- if ( $serialized ) $cookies[] = $serialized;
- }
-
- return implode("; ", $cookies);