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


PHP Cookie::read方法代码示例

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


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

示例1: __beforeAction

 public function __beforeAction()
 {
     // User authentication
     $user_model = new User_Model();
     User_Model::$auth_status = User_Model::AUTH_STATUS_NOT_LOGGED;
     // Authentication by post
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         try {
             if (!preg_match('#^[a-z0-9-]+$#', $username)) {
                 throw new Exception('Invalid username');
             }
             if ($user_model->authenticate($username, $password)) {
                 User_Model::$auth_status = User_Model::AUTH_STATUS_LOGGED;
                 // Write session and cookie to remember sign-in
                 Cookie::write('login', Encryption::encode($username . ':' . $password), 60 * 24 * 3600);
                 Session::write('username', $username);
             } else {
                 throw new Exception('Bad username or password');
             }
         } catch (Exception $e) {
             User_Model::$auth_status = User_Model::AUTH_STATUS_BAD_USERNAME_OR_PASSWORD;
             Cookie::delete('login');
             Session::delete('username');
         }
     } else {
         // Authentication by session
         if (($username = Session::read('username')) !== null) {
             try {
                 $user_model->loadUser($username);
                 User_Model::$auth_status = User_Model::AUTH_STATUS_LOGGED;
             } catch (Exception $e) {
                 Session::delete('username');
                 Cookie::delete('login');
             }
             // Authentication by cookies
         } else {
             if (($login = Cookie::read('login')) !== null) {
                 try {
                     if (isset($login) && ($login = Encryption::decode($login))) {
                         $login = explode(':', $login);
                         $username = $login[0];
                         if (!preg_match('#^[a-z0-9-]+$#', $username)) {
                             throw new Exception('Invalid username');
                         }
                         array_splice($login, 0, 1);
                         $password = implode(':', $login);
                         if ($user_model->authenticate($username, $password)) {
                             User_Model::$auth_status = User_Model::AUTH_STATUS_LOGGED;
                             // Write session to remember sign-in
                             Session::write('username', $username);
                         } else {
                             throw new Exception('Bad username or password');
                         }
                     } else {
                         throw new Exception('Invalid user cookie');
                     }
                 } catch (Exception $e) {
                     Cookie::delete('login');
                 }
             }
         }
     }
 }
开发者ID:hugonicolas,项目名称:Site,代码行数:65,代码来源:Layout.php

示例2: loggedIn

 /**
  *  Verifica se o usuário está autenticado.
  *
  *  @return boolean Verdadeiro caso o usuário esteja autenticado
  */
 public function loggedIn()
 {
     if (is_null($this->loggedIn)) {
         $user = Cookie::read("user_id");
         $password = Cookie::read("password");
         if (!is_null($user) && !is_null($password)) {
             $user = $this->identify(array($this->fields["id"] => $user, $this->fields["password"] => $password));
             $this->loggedIn = !empty($user);
         } else {
             $this->loggedIn = false;
         }
     }
     return $this->loggedIn;
 }
开发者ID:vfeitoza,项目名称:spaghettiphp,代码行数:19,代码来源:auth_component.php

示例3: current_timezone

function current_timezone()
{
    return Cookie::read('anchor-install-timezone', 0) * 3600;
}
开发者ID:hackiosa,项目名称:anchor-cms,代码行数:4,代码来源:run.php


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