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


PHP Cookie::create方法代码示例

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


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

示例1: testCookieCollection

 /**
  * @expectedException WrongStateException
  */
 public function testCookieCollection()
 {
     if (!isset($_SERVER["DOCUMENT_ROOT"]) || !$_SERVER["DOCUMENT_ROOT"]) {
         $this->markTestSkipped('can\'t test cookies without web');
     }
     echo "";
     CookieCollection::create()->add(Cookie::create('anotherTestCookie')->setValue('testValue')->setMaxAge(60 * 60))->httpSetAll();
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:11,代码来源:CookieTest.class.php

示例2: attempt

 public static function attempt($array, $remember = false)
 {
     //Table::show(self::$hashedFields);
     //
     $hashed = array();
     //
     foreach ($array as $key => $value) {
         if (Table::contains(self::$hashedFields, $key)) {
             Table::add($hashed, Hash::make($array[$key]), $key);
         }
     }
     //
     //Table::show($hashed);
     //
     $where = "";
     $ok = false;
     //
     $i = 0;
     foreach ($array as $key => $value) {
         if ($i > 0) {
             $where .= " and ";
         }
         if (Table::contains(self::$hashedFields, $key)) {
             $where .= "{$key}='" . $hashed[$key] . "' ";
         } else {
             $where .= "{$key}='{$value}' ";
         }
         $i++;
     }
     $sql = "select * from " . self::$table . " where " . $where;
     //echo $sql;
     //
     if (Database::countS($sql) > 0) {
         //returning true value
         $ok = true;
         //
         // session
         $user = Database::read($sql);
         $saved = Config::get('auth.saved_fields');
         //
         $static = array();
         //
         foreach ($user[0] as $key => $value) {
             if (array_key_exists($key, $saved)) {
                 $static[$key] = $value;
             }
         }
         //
         Session::put('auths', $static);
         //
         // remember cookie
         if ($remember) {
             Cookie::create(Config::get('auth.rememeber_cookie'), $user[0]["rememberToken"], time() + 3600 * 24 * 7);
         }
     }
     //
     return $ok;
 }
开发者ID:amineabri,项目名称:Fiesta,代码行数:58,代码来源:Auth.php

示例3: modify

 /**
  * @param RequestInterface $request
  * @param string $name
  * @param callable $modify
  *
  * @return RequestInterface
  */
 public static function modify(RequestInterface $request, $name, $modify)
 {
     if (!is_callable($modify)) {
         throw new InvalidArgumentException('$modify must be callable.');
     }
     $cookies = Cookies::fromRequest($request);
     $cookie = $modify($cookies->has($name) ? $cookies->get($name) : Cookie::create($name));
     return $cookies->with($cookie)->renderIntoCookieHeader($request);
 }
开发者ID:philsam,项目名称:dflydev-fig-cookies,代码行数:16,代码来源:FigRequestCookies.php

示例4: doRun

function doRun()
{
    $msg = '';
    $username = mysql_real_escape_string($_POST['name']);
    $pass = mysql_real_escape_string($_POST['pass']);
    try {
        $db = new PDO('mysql:host=localhost;dbname=testData', 'root', 'root');
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $db->prepare('	SELECT 
													username, pass 
											FROM 	
													testTable
											WHERE
													username = :name
											AND 	
													pass = :pass

										');
        $stmt->bindParam(':name', $username, PDO::PARAM_STR);
        $stmt->bindParam(':pass', $pass, PDO::PARAM_STR);
        $stmt->execute();
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        if ($result == false) {
            $msg = 'sorry could not connect';
        } else {
            //$_SESSION['name'] = $username;
            /**
             * Create a cookie with the name "myCookieName" and value "testing cookie value"
             */
            $cookie = new Cookie();
            // Set cookie name
            $cookie->setName('Login');
            // Set cookie value
            $cookie->setValue("testing cookie value");
            // Set cookie expiration time
            $cookie->setTime("+1 hour");
            // Create the cookie
            $cookie->create();
            // Delete the cookie.
            //$cookie->delete();
            $msg = 'logged in as ' . $username . '<br>';
        }
    } catch (PDOException $e) {
        echo "Error:" . $e;
    }
    echo $msg;
    $db = NULL;
}
开发者ID:reshadf,项目名称:Library,代码行数:48,代码来源:index.php

示例5: provideGetsCookieByNameData

 public function provideGetsCookieByNameData()
 {
     return [['theme=light', 'theme', Cookie::create('theme', 'light')], ['theme=', 'theme', Cookie::create('theme')], ['hello=world; theme=light; sessionToken=abc123', 'theme', Cookie::create('theme', 'light')], ['hello=world; theme=; sessionToken=abc123', 'theme', Cookie::create('theme')]];
 }
开发者ID:philsam,项目名称:dflydev-fig-cookies,代码行数:4,代码来源:CookiesTest.php

示例6: get_user_data

// Check to see if the user is already logged in
if ($cookie_handler->cookie_exists("compsec")) {
    print "Error: Cannot log in if user is already logged in!";
} else {
    // Check to see if the user is already in the database.
    // The function will return an array if they are.
    $results = get_user_data($uuid);
    if (is_array($results)) {
        $uuid = $results[1];
        $database_password = $results[2];
        $salt = $results[3];
        // Validate that the supplied password is correct
        $hashed_password = hash("sha512", $password . $salt);
        if ($database_password == $hashed_password) {
            // Store cookie on client's computer
            $cookie = Cookie::create($uuid, $hashed_password);
            $result = $cookie_handler->set_cookie("compsec", $cookie);
            if ($result == false) {
                print "An unexpected error has prevented you from logging in. Reason: Unable to create a login cookie.";
            }
            // Login successful
            update_last_login($uuid);
            header("location:index.php");
        } else {
            print "Error: Invalid password. Press the back button to try again.";
        }
    } else {
        print "Error: User does not exist! Press the back button to try again.";
    }
}
?>
开发者ID:newmight2015,项目名称:csc235_project1,代码行数:31,代码来源:process_login.php

示例7: setDefault

 public static function setDefault()
 {
     Cookie::create(self::getName(), Config::get('lang.default'), 60 * 24 * 7);
     Res::stsession("Fiesta_lang", Config::get('lang.default'));
 }
开发者ID:amineabri,项目名称:Fiesta,代码行数:5,代码来源:Lang.php

示例8: it_sets_cookies

 /**
  * @test
  */
 public function it_sets_cookies()
 {
     $request = (new FigCookieTestingRequest())->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world');
     $request = FigRequestCookies::set($request, Cookie::create('hello', 'WORLD!'));
     $this->assertEquals('theme=light; sessionToken=RAPELCGRQ; hello=WORLD%21', $request->getHeaderLine('Cookie'));
 }
开发者ID:philsam,项目名称:dflydev-fig-cookies,代码行数:9,代码来源:FigRequestCookiesTest.php


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