当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::setCookie方法代码示例

本文整理汇总了PHP中Slim::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::setCookie方法的具体用法?PHP Slim::setCookie怎么用?PHP Slim::setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim的用法示例。


在下文中一共展示了Slim::setCookie方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSlimSetsCookie

 /**
  * Test Slim sets cookie with default time
  *
  * Pre-conditions:
  * Slim app initialized;
  * Case A: Cookie time not set;
  * Case B: Cookie time set as seconds from now (integer);
  * Case C: Cookie time set as string;
  * Case D: Cookie time is set to 0;
  *
  * Post-conditions:
  * Cookie available in response;
  * Case A: Cookie time set using default value;
  * Case C: Cookie time set using `strtotime()`;
  * Case D: Cookie time is 0;
  */
 public function testSlimSetsCookie() {
     Slim::init();
     $cj = Slim::response()->getCookieJar();
     //Case A
     $timeA = time();
     Slim::setCookie('myCookie1', 'myValue1');
     $cookieA = $cj->getResponseCookie('myCookie1');
     $this->assertEquals('myCookie1', $cookieA->getName());
     $this->assertEquals('myValue1', $cookieA->getValue());
     $this->assertEquals($timeA + 1200, $cookieA->getExpires()); //default duration is 20 minutes
     $this->assertEquals('/', $cookieA->getPath());
     $this->assertEquals('', $cookieA->getDomain());
     $this->assertFalse($cookieA->getSecure());
     $this->assertFalse($cookieA->getHttpOnly());
     //Case C
     $timeC = time();
     Slim::setCookie('myCookie3', 'myValue3', '1 hour');
     $cookieC = $cj->getResponseCookie('myCookie3');
     $this->assertEquals($timeC + 3600, $cookieC->getExpires());
     //Case D
     $timeD = time();
     Slim::setCookie('myCookie4', 'myValue4', 0);
     $cookieD = $cj->getResponseCookie('myCookie4');
     $this->assertEquals(0, $cookieD->getExpires());
 }
开发者ID:ntdt,项目名称:Slim,代码行数:41,代码来源:SlimTest.php

示例2: function

    return $argument;
});
// End FILTERS
/* == *
 *
 * ROUTES
 *
 * ==============================================*/
$app->map('/', function () use($app) {
    if ($app->request()->isPost() && sizeof($app->request()->post()) == 2) {
        // if valid login, set auth cookie and redirect
        $testp = sha1('uAX8+Tdv23/3YQ==');
        $post = (object) $app->request()->post();
        if (isset($post->username) && isset($post->password) && sha1($post->password) == $testp && $post->username == 'bppenne') {
            //$app->setEncryptedCookie('bppasscook', $post->password, 0);
            $app->setCookie('user_cook', $post->username, 0);
            $app->setCookie('pass_cook', $post->password, 0);
            $app->redirect('./review');
        } else {
            $app->redirect('.');
        }
    }
    $app->render('login.html');
})->via('GET', 'POST')->name('login');
$authUser = function ($role = 'member') use($app) {
    return function () use($role) {
        $app = Slim::getInstance();
        // Check for password in the cookie
        if ($app->getCookie('pass_cook') != 'uAX8+Tdv23/3YQ==' || $app->getCookie('user_cook') != 'bppenne') {
            //if ( $app->getEncryptedCookie('bppasscook', false) != 'uAX8+Tdv23/3YQ==') {
            $app->redirect('..');
开发者ID:nerdfiles,项目名称:slim_bp,代码行数:31,代码来源:index.php

示例3: testDeleteCookie

 /**
  * Test delete cookie
  *
  * This method ensures that the `Set-Cookie:` HTTP response
  * header is set. The implementation of setting the response
  * cookie is tested separately in another file.
  */
 public function testDeleteCookie()
 {
     Slim_Environment::mock(array('SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar', 'COOKIE' => 'foo=bar; foo2=bar2'));
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->setCookie('foo', 'bar');
         $s->deleteCookie('foo');
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $cookies = explode("\n", $header['Set-Cookie']);
     $this->assertEquals(1, count($cookies));
     $this->assertEquals(1, preg_match('@^foo=;@', $cookies[0]));
 }
开发者ID:rs3d,项目名称:Slimplr,代码行数:21,代码来源:SlimTest.php

示例4: testSlimDeletesCookies

 /**
  * Test Slim deletes cookies
  *
  * Pre-conditions:
  * Case A: Classic cookie
  * Case B: Encrypted cookie
  *
  * Post-conditions:
  * Response Cookies replaced with empty, auto-expiring Cookies
  */
 public function testSlimDeletesCookies()
 {
     $app = new Slim();
     $cj = $app->response()->getCookieJar();
     //Case A
     $app->setCookie('foo1', 'bar1');
     $this->assertEquals('bar1', $cj->getResponseCookie('foo1')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() > time());
     $app->deleteCookie('foo1');
     $this->assertEquals('', $app->getCookie('foo1'));
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() < time());
     //Case B
     $app->setEncryptedCookie('foo2', 'bar2');
     $this->assertTrue(strlen($cj->getResponseCookie('foo2')->getValue()) > 0);
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() > time());
     $app->deleteCookie('foo2');
     $this->assertEquals('', $cj->getResponseCookie('foo2')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() < time());
 }
开发者ID:inscriptionweb,项目名称:lebonmail,代码行数:29,代码来源:SlimTest.php

示例5: testDeleteCookie

 /**
  * Test delete cookie
  *
  * This method ensures that the `Set-Cookie:` HTTP response
  * header is set. The implementation of setting the response
  * cookie is tested separately in another file.
  */
 public function testDeleteCookie()
 {
     Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar', 'QUERY_STRING' => 'one=foo&two=bar', 'SERVER_NAME' => 'slimframework.com', 'SERVER_PORT' => 80, 'HTTP_COOKIE' => 'foo=bar; foo2=bar2', 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => @fopen('php://stderr', 'w')));
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->setCookie('foo', 'bar');
         $s->deleteCookie('foo');
     });
     $env = $s->environment();
     list($status, $header, $body) = $s->call($env);
     $cookies = explode("\n", $header['Set-Cookie']);
     $this->assertEquals(1, count($cookies));
     $this->assertEquals(1, preg_match('@^foo=;@', $cookies[0]));
 }
开发者ID:nerdfiles,项目名称:slim_bp,代码行数:21,代码来源:SlimTest.php

示例6: testSlimDeletesCookies

 /**
  * Test Slim deletes cookies
  *
  * Pre-conditions:
  * Case A: Classic cookie
  * Case B: Encrypted cookie
  *
  * Post-conditions:
  * Response Cookies replaced with empty, auto-expiring Cookies
  */
 public function testSlimDeletesCookies()
 {
     Slim::init();
     $cj = Slim::response()->getCookieJar();
     //Case A
     Slim::setCookie('foo1', 'bar1');
     $this->assertEquals('bar1', $cj->getResponseCookie('foo1')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() > time());
     Slim::deleteCookie('foo1');
     $this->assertEquals('', Slim::getCookie('foo1'));
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() < time());
     //Case B
     Slim::setEncryptedCookie('foo2', 'bar2');
     $this->assertTrue(strlen($cj->getResponseCookie('foo2')->getValue()) > 0);
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() > time());
     Slim::deleteCookie('foo2');
     $this->assertEquals('', $cj->getResponseCookie('foo2')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() < time());
 }
开发者ID:alanvivona,项目名称:scawTP,代码行数:29,代码来源:SlimTest.php


注:本文中的Slim::setCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。