本文整理汇总了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');
}
}
}
}
}
示例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;
}
示例3: current_timezone
function current_timezone()
{
return Cookie::read('anchor-install-timezone', 0) * 3600;
}