/** * ログイン処理 Action * * @return void */ public function loginAction() { $req = $this->getRequest(); $res = $this->getResponse(); $controllerName = $req->getControllerName(); $loginName = $req->getparam('userName'); $password = $req->getparam('password'); $garoonApi = new GaroonApiLib(); $result = $garoonApi->utilLogin($loginName, $password); if ($result->status === 'Login') { $loginResult = explode('=', $result->cookie); // ログイン情報をcookieに出力 $cookie = new Zend_Http_Cookie($loginResult[0], $loginResult[1], 'localhost'); $res->setHeader('Set-Cookie', $cookie->__toString()); // ログインユーザー情報取得 $searchUserName = array(); $searchUserName[] = $loginName; $userInfo = $garoonApi->baseGetUsersByLoginName($searchUserName, $loginResult[1]); $userId = $userInfo->user->key; $userName = $userInfo->user->name; $loginUserInfo = array(); $loginUserInfo['loginName'] = $loginName; $loginUserInfo['userId'] = $userId; $loginUserInfo['userName'] = $userName; $this->view->assign('loginInfo', $loginUserInfo); $displayContent = $this->view->render($controllerName . '/input.tpl'); } else { $this->view->assign('errorMessage', 'ログインに失敗しました。'); $displayContent = $this->view->render($controllerName . '/error.tpl'); } // 表示 $res->setBody($displayContent); }
public function addCookie($cookie, $ref_uri = null) { if (is_string($cookie)) { if ($this->_encodeCookie) { $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri); } else { $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri, false); } } if ($cookie instanceof Zend_Http_Cookie) { $domain = $cookie->getDomain(); $path = $cookie->getPath(); if (!isset($this->cookies[$domain])) { $this->cookies[$domain] = array(); } if (!isset($this->cookies[$domain][$path])) { $this->cookies[$domain][$path] = array(); } $this->cookies[$domain][$path][$cookie->getName()] = $cookie; $this->_rawCookies[] = $cookie; } else { require_once 'Zend/Http/Exception.php'; throw new Zend_Http_Exception('Supplient argument is not a valid cookie string or object'); } }
public function testIsSecure() { foreach ($this->secureTests as $cookieStr) { $cookie = Zend_Http_Cookie::factory($cookieStr); $this->assertTrue($cookie->isSecure()); } foreach ($this->nonSecureTests as $cookieStr) { $cookie = Zend_Http_Cookie::factory($cookieStr); $this->assertFalse($cookie->isSecure()); } }
public function unsetCookie() { // Check if HttpCookieObject exists $this->getHttpCookieObject(); $name = $this->httpCookieObject->getName(); $expire = $this->httpCookieObject->getExpiryTime(); $path = $this->httpCookieObject->getPath(); $domain = $this->httpCookieObject->getDomain(); $secure = $this->httpCookieObject->isSecure(); $value = null; $httpCookieObject = new Zend_Http_Cookie($name, $value, $domain, $expire, $path, $secure); $this->setHttpCookieObject($httpCookieObject); return $this->write(); }
/** * Add a cookie to the jar. Cookie should be passed either as a Zend_Http_Cookie object * or as a string - in which case an object is created from the string. * * @param Zend_Http_Cookie|string $cookie * @param Zend_Uri_Http|string $red_uri Optional reference URI (for domain, path, secure) */ public function addCookie($cookie, $ref_uri = null) { if (is_string($cookie)) { $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri); } if ($cookie instanceof Zend_Http_Cookie) { $domain = $cookie->getDomain(); $path = $cookie->getPath(); if (!isset($this->cookies[$domain])) { $this->cookies[$domain] = array(); } if (!isset($this->cookies[$domain][$path])) { $this->cookies[$domain][$path] = array(); } $this->cookies[$domain][$path][$cookie->getName()] = $cookie; } else { throw Zend::exception('Zend_Http_Exception', 'Supplient argument is not a valid cookie string or object'); } }
public function testIteratorAndCountable() { $jar = new Zend_Http_CookieJar(); $cookies = array(Zend_Http_Cookie::fromString('foo1=bar1; domain=.example.com; path=/a/b'), Zend_Http_Cookie::fromString('foo2=bar2; domain=.example.com; path=/a/b/')); foreach ($cookies as $cookie) { $jar->addCookie($cookie); } foreach ($jar as $cookie) { $this->assertTrue($cookie instanceof Zend_Http_Cookie); } $this->assertEquals(2, count($jar)); $this->assertFalse($jar->isEmpty()); $jar->reset(); $this->assertTrue($jar->isEmpty()); }
/** * Make sure we can set cookie objects with a jar * */ public function testSetCookieObjectJar() { $this->client->setUri($this->baseuri . 'testCookies.php'); $this->client->setCookieJar(); $refuri = $this->client->getUri(); $cookies = array(Zend_Http_Cookie::fromString('chocolate=chips', $refuri), Zend_Http_Cookie::fromString('crumble=apple', $refuri)); $strcookies = array(); foreach ($cookies as $c) { $this->client->setCookie($c); $strcookies[$c->getName()] = $c->getValue(); } $res = $this->client->request(); $this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies'); }
public function testFromStringFalse() { $cookie = Zend_Http_Cookie::fromString('foo; domain=www.exmaple.com'); $this->assertEquals(false, $cookie, 'fromString was expected to fail and return false'); $cookie = Zend_Http_Cookie::fromString('=bar; secure; domain=foo.nl'); $this->assertEquals(false, $cookie, 'fromString was expected to fail and return false'); $cookie = Zend_Http_Cookie::fromString('fo;o=bar; secure; domain=foo.nl'); $this->assertEquals(false, $cookie, 'fromString was expected to fail and return false'); }
/** * Test we can get all matching cookies for a request, and return as strings array / concat */ public function testGetMatchingCookiesAsStrings() { $jar = new Zend_Http_CookieJar(); $cookies = array(Zend_Http_Cookie::fromString('foo1=bar1; domain=.foo.com; path=/path; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo2=bar2; domain=.foo.com; path=/; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo3=bar3; domain=.foo.com; path=/; expires=' . date(DATE_COOKIE, time() - 3600)), Zend_Http_Cookie::fromString('foo4=bar4; domain=.foo.com; path=/;'), Zend_Http_Cookie::fromString('foo5=bar5; domain=.foo.com; path=/; secure; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo6=bar6; domain=.foo.com; path=/otherpath; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo7=bar7; domain=www.foo.com; path=/path; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo8=bar8; domain=subdomain.foo.com; path=/path; expires=' . date(DATE_COOKIE, time() + 3600))); foreach ($cookies as $cookie) { $jar->addCookie($cookie); } $this->assertEquals(8, count($jar->getAllCookies()), 'Cookie count is expected to be 8'); $cookies = $jar->getMatchingCookies('http://www.foo.com/path/file.txt', true, Zend_Http_CookieJar::COOKIE_STRING_ARRAY); $this->assertType('array', $cookies, '$cookies is expected to be an array, but it is not'); $this->assertType('string', $cookies[0], '$cookies[0] is expected to be a string'); $cookies = $jar->getMatchingCookies('http://www.foo.com/path/file.txt', true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT); $this->assertType('string', $cookies, '$cookies is expected to be a string'); }
/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. */ public function setCookie($cookie, $value = null) { if (!is_null($value)) { $value = urlencode($value); } if (isset($this->Cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->Cookiejar->addCookie($cookie); } elseif (is_string($cookie) && !is_null($value)) { if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) { throw new Zend_Http_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$name})"); } $cookie = Zend_Http_Cookie::factory("{$cookie}={$value}", $this->uri); $this->Cookiejar->addCookie($cookie); } } else { parent::setCookie($cookie, $value); } }
/** * Test that cookies with far future expiry date (beyond the 32 bit unsigned int range) are * not mistakenly marked as 'expired' * * @link http://framework.zend.com/issues/browse/ZF-5690 */ public function testZF5690OverflowingExpiryDate() { $expTime = "Sat, 29-Jan-2039 00:54:42 GMT"; $cookie = Zend_Http_Cookie::fromString("foo=bar; domain=.example.com; expires={$expTime}"); $this->assertFalse($cookie->isExpired(), 'Expiry: ' . $cookie->getExpiryTime()); }
/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. * @return Zend_Http_Client */ public function setCookie($cookie, $value = null) { if (! class_exists('Zend_Http_Cookie')) require_once 'Zend/Http/Cookie.php'; if (is_array($cookie)) { foreach ($cookie as $c => $v) { if (is_string($c)) { $this->setCookie($c, $v); } else { $this->setCookie($v); } } return $this; } if ($value !== null) $value = urlencode($value); if (isset($this->cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->cookiejar->addCookie($cookie); } elseif (is_string($cookie) && $value !== null) { $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri); $this->cookiejar->addCookie($cookie); } } else { if ($cookie instanceof Zend_Http_Cookie) { $name = $cookie->getName(); $value = $cookie->getValue(); $cookie = $name; } if (preg_match("/[=,; \t\r\n\013\014]/", $cookie)) throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})"); $value = addslashes($value); if (! isset($this->headers['cookie'])) $this->headers['cookie'] = ''; $this->headers['cookie'] .= $cookie . '=' . $value . '; '; } return $this; }
/** * Make sure that paths with trailing slashes are matched as well as paths with no trailing slashes */ public function testMatchPathWithTrailingSlash() { $jar = new Zend_Http_CookieJar(); $cookies = array( Zend_Http_Cookie::fromString('foo1=bar1; domain=.example.com; path=/a/b'), Zend_Http_Cookie::fromString('foo2=bar2; domain=.example.com; path=/a/b/') ); foreach ($cookies as $cookie) $jar->addCookie($cookie); $cookies = $jar->getMatchingCookies('http://www.example.com/a/b/file.txt'); $this->assertType('array', $cookies); $this->assertEquals(2, count($cookies)); }
/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. * @return Zend_Http_Client * @throws Zend_Http_Client_Exception */ public function setCookie($cookie, $value = null) { Zend_Loader::loadClass('Zend_Http_Cookie'); if (is_array($cookie)) { foreach ($cookie as $c => $v) { if (is_string($c)) { $this->setCookie($c, $v); } else { $this->setCookie($v); } } return $this; } if ($value !== null && $this->config['encodecookies']) { $value = urlencode($value); } if (isset($this->cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->cookiejar->addCookie($cookie); } elseif (is_string($cookie) && $value !== null) { $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri, $this->config['encodecookies']); $this->cookiejar->addCookie($cookie); } } else { if ($cookie instanceof Zend_Http_Cookie) { $name = $cookie->getName(); $value = $cookie->getValue(); $cookie = $name; } if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) { /** @see Zend_Http_Client_Exception */ require_once 'Zend/Http/Client/Exception.php'; throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$cookie})"); } $value = addslashes($value); if (!isset($this->headers['cookie'])) { $this->headers['cookie'] = array('Cookie', ''); } $this->headers['cookie'][1] .= $cookie . '=' . $value . '; '; } return $this; }
/** * @group ZF-10506 */ public function testPregMatchIsQuoted() { $this->assertFalse(Zend_Http_Cookie::matchCookieDomain('foo.bar.com', 'www.foozbar.com')); }
/** * Return a subset of a domain-matching cookies that also match a specified path * * @param array $dom_array * @param string $path * @return array */ protected function _matchPath($domains, $path) { $ret = array(); foreach ($domains as $dom => $paths_array) { foreach (array_keys($paths_array) as $cpath) { if (Zend_Http_Cookie::matchCookiePath($cpath, $path)) { if (!isset($ret[$dom])) { $ret[$dom] = array(); } $ret[$dom][$cpath] = $paths_array[$cpath]; } } } return $ret; }
/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. * @return Zend_Http_Client */ public function setCookie($cookie, $value = null) { if ($value !== null) { $value = urlencode($value); } if (isset($this->Cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->Cookiejar->addCookie($cookie); } elseif (is_string($cookie) && $value !== null) { $cookie = Zend_Http_Cookie::factory("{$cookie}={$value}", $this->uri); $this->Cookiejar->addCookie($cookie); } } else { if ($cookie instanceof Zend_Http_Cookie) { $cookie = $cookie->getName(); $value = $cookie->getValue(); } if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) { throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$name})"); } $value = urlencode($value); $this->setHeaders('cookie', "{$cookie}={$value}", false); } return $this; }