/** * Get the value of an encrypted Cookie from the current HTTP request * * Return the value of an encrypted cookie from the current HTTP request, * or return NULL if cookie does not exist. Encrypted cookies created during * the current request will not be available until the next request. * * @param string $name * @return string|false */ public function getEncryptedCookie($name, $deleteIfInvalid = true) { $value = Slim_Http_Util::decodeSecureCookie($this->request->cookies($name), $this->config('cookies.secret_key'), $this->config('cookies.cipher'), $this->config('cookies.cipher_mode')); if ($value === false && $deleteIfInvalid) { $this->deleteCookie($name); } return $value; }
/** * Get the value of a Cookie from the current HTTP Request * * Return the value of a cookie from the current HTTP request, * or return NULL if cookie does not exist. Cookies created during * the current request will not be available until the next request. * * @param string $name * @return string|null */ public function getCookie($name) { return $this->request->cookies($name); }
/** * Test fetch COOKIE params */ public function testCookies() { $env = Slim_Environment::mock(array('COOKIE' => 'foo=bar; abc=123')); $req = new Slim_Http_Request($env); $this->assertEquals(2, count($req->cookies())); $this->assertEquals('bar', $req->cookies('foo')); $this->assertNull($req->cookies('xyz')); }
/** * Load session * @param array $env * @return void */ protected function loadSession(&$env) { $req = new Slim_Http_Request($env); $value = Slim_Http_Util::decodeSecureCookie($req->cookies($this->settings['name']), $this->settings['secret'], $this->settings['cipher'], $this->settings['cipher_mode']); if ($value) { $_SESSION = unserialize($value); } else { $_SESSION = array(); } }
/** * Test fetch COOKIE params */ public function testCookies() { Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '/foo/index.php', 'PATH_INFO' => '/bar/xyz', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_COOKIE' => 'foo=bar; abc=123')); $env = Slim_Environment::getInstance(); $req = new Slim_Http_Request($env); $this->assertEquals(2, count($req->cookies())); $this->assertEquals('bar', $req->cookies('foo')); $this->assertNull($req->cookies('xyz')); }
public function testParams() { //Case A: PUT params $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST = array('_METHOD' => 'PUT', 'foo1' => 'bar1'); $r = new Slim_Http_Request(); $this->assertEquals('bar1', $r->params('foo1')); $this->assertEquals('bar1', $r->put('foo1')); $this->assertEquals(array('foo1' => 'bar1'), $r->put()); //Case B: POST params $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST = array('foo1' => 'bar1'); $r = new Slim_Http_Request(); $this->assertEquals('bar1', $r->params('foo1')); $this->assertEquals('bar1', $r->post('foo1')); $this->assertEquals($_POST, $r->post()); //Case C: GET params $_SERVER['REQUEST_METHOD'] = 'GET'; $_POST = array(); $_GET = array('foo1' => 'bar1'); $r = new Slim_Http_Request(); $this->assertEquals('bar1', $r->params('foo1')); $this->assertEquals('bar1', $r->get('foo1')); $this->assertEquals($_GET, $r->get()); //Case D: COOKIE params $_COOKIE['foo'] = 'bar'; $r = new Slim_Http_Request(); $this->assertEquals($_COOKIE, $r->cookies()); $this->assertEquals('bar', $r->cookies('foo')); //Case E: NULL params $_SERVER['REQUEST_METHOD'] = 'POST'; $_GET = array(); $_POST = array(); $r = new Slim_Http_Request(); $this->assertNull($r->params('foo1')); $this->assertNull($r->put('foo1')); $this->assertNull($r->post('foo1')); $this->assertNull($r->get('foo1')); $this->assertNull($r->cookies('foo1')); }