本文整理汇总了PHP中Cookie::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Cookie::set方法的具体用法?PHP Cookie::set怎么用?PHP Cookie::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetData
public function testSetData()
{
$this->cookie->set('fairy', 'test');
$this->cookie->set_cookie_data(array('fairy' => 'Blum'));
$this->assertEquals(0, count($this->cookie->get_updates()));
$this->assertEquals('Blum', $this->cookie->get('fairy', 'test'));
}
示例2: __createCookie
private function __createCookie($username, $password)
{
if ($this->_Parent->Configuration->get('use-sessions', 'frontend-authentication') == 'yes') {
$_SESSION[__SYM_COOKIE_PREFIX_ . 'front-end-authentication'] = array('username' => $username, 'password' => md5($password));
} else {
$Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'front-end-authentication', 24 * 60 * 60, __SYM_COOKIE_PATH__);
$Cookie->set('username', $username);
$Cookie->set('password', md5($password));
}
}
示例3: __trigger
protected function __trigger()
{
$supported_language_codes = LanguageRedirect::instance()->getSupportedLanguageCodes();
// only do something when there is a set of supported languages defined
if (!empty($supported_language_codes)) {
$current_language_code = LanguageRedirect::instance()->getLanguageCode();
// no redirect, set current language and region in cookie
if (isset($current_language_code) and in_array($current_language_code, $supported_language_codes)) {
$Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'language-redirect', TWO_WEEKS, __SYM_COOKIE_PATH__);
$Cookie->set('language', LanguageRedirect::instance()->getLanguage());
$Cookie->set('region', LanguageRedirect::instance()->getRegion());
} else {
$current_path = !isset($current_language_code) ? $this->_env['param']['current-path'] : substr($this->_env['param']['current-path'], strlen($current_language_code) + 1);
$browser_languages = $this->getBrowserLanguages();
foreach ($browser_languages as $language) {
if (in_array($language, $supported_language_codes)) {
$in_browser_languages = true;
$browser_language = $language;
break;
}
}
$Cookie = new Cookie(__SYM_COOKIE_PREFIX_ . 'language-redirect', TWO_WEEKS, __SYM_COOKIE_PATH__);
$cookie_language_code = $Cookie->get('language');
if (strlen($cookie_language_code) > 0) {
$language_code = $Cookie->get('region') ? $cookie_language_code . '-' . $Cookie->get('region') : $cookie_language_code;
} elseif ($in_browser_languages) {
$language_code = $browser_language;
} else {
$language_code = $supported_language_codes[0];
}
// redirect and exit
header('Location: ' . $this->_env['param']['root'] . '/' . $language_code . '/' . $current_path);
die;
}
$all_languages = LanguageRedirect::instance()->getAllLanguages();
$result = new XMLElement('language-redirect');
$current_language_xml = new XMLElement('current-language', $all_languages[$current_language_code] ? $all_languages[$current_language_code] : $current_language_code);
$current_language_xml->setAttribute('handle', $current_language_code);
$result->appendChild($current_language_xml);
$supported_languages_xml = new XMLElement('supported-languages');
foreach ($supported_language_codes as $language) {
$language_code = new XMLElement('item', $all_languages[$language] ? $all_languages[$language] : $language);
$language_code->setAttribute('handle', $language);
$supported_languages_xml->appendChild($language_code);
}
$result->appendChild($supported_languages_xml);
return $result;
}
return false;
}
示例4: testExtend
/**
* @runInSeparateProcess
*/
public function testExtend()
{
$cookie = new Cookie();
$cookie->set('testSet');
$result = $cookie->extend('testExtend');
$this->assertTrue($result);
$this->assertEquals(serialize(array('testSet', 'testExtend')), $_COOKIE['openimporter_cookie']);
$cookie->set('testSet', 'another_name');
$result = $cookie->extend('testExtend', 'another_name');
$this->assertTrue($result);
$this->assertEquals(serialize(array('testSet', 'testExtend')), $_COOKIE['another_name']);
$cookie->set('testSet');
$result = $cookie->extend(null);
$this->assertFalse($result);
}
示例5: index
public function index()
{
$map['id'] = array('neq', 1);
$model = D('Shop_user');
$count = $model->where($map)->count();
if ($count > 0) {
import("@.ORG.Util.Page");
//创建分页对象
if (!empty($_REQUEST['listRows'])) {
$listRows = $_REQUEST['listRows'];
} else {
$listRows = '';
}
$p = new Page($count, $listRows);
//分页查询数据
$voList = $model->where($map)->order('id desc')->limit($p->firstRow . ',' . $p->listRows)->select();
//获取文章分类名称
//分页跳转的时候保证查询条件
foreach ($map as $key => $val) {
if (!is_array($val)) {
$p->parameter .= "{$key}=" . urlencode($val) . "&";
}
}
//分页显示
$page = $p->show();
//模板赋值显示
$this->assign('list', $voList);
$this->assign("page", $page);
}
$this->assign('totalCount', $count);
$this->assign('numPerPage', $p->listRows);
$this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
Cookie::set('_currentUrl_', __SELF__);
$this->display();
}
示例6: index
public function index()
{
$map = $this->_search();
if (method_exists($this, '_filter')) {
$this->_filter($map);
}
$map['type'] = 2;
$model = D('Basic_download');
$count = $model->where($map)->count();
if ($count > 0) {
import("@.ORG.Util.Page");
if (!empty($_REQUEST['listRows'])) {
$listRows = $_REQUEST['listRows'];
} else {
$listRows = '';
}
$p = new Page($count, $listRows);
$voList = $model->where($map)->order('id desc')->limit($p->firstRow . ',' . $p->listRows)->select();
foreach ($map as $key => $val) {
if (!is_array($val)) {
$p->parameter .= "{$key}=" . urlencode($val) . "&";
}
}
$page = $p->show();
$this->assign('list', $voList);
$this->assign("page", $page);
}
$this->assign('totalCount', $count);
$this->assign('numPerPage', $p->listRows);
$this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
Cookie::set('_currentUrl_', __SELF__);
$this->display();
}
示例7: device_change
/**
* デバイス変更
*/
public function device_change()
{
$request = Request::getInstance();
// デバイスの設定
$device_type = 0;
$device = $request->get('device');
switch ($device) {
case 'pc':
$device_type = Config::get('DEVICE_PC');
break;
case 'm':
case 'mb':
$device_type = Config::get('DEVICE_MB');
break;
case 'sp':
$device_type = Config::get('DEVICE_SP');
break;
case 'tb':
$device_type = Config::get('DEVICE_TB');
break;
default:
Cookie::set('device', null);
$this->redirectBack(array('controller' => 'entries', 'action' => 'index'));
}
Cookie::set('device', $device_type);
$this->redirectBack(array('controller' => 'entries', 'action' => 'index'));
}
示例8: edit
public function edit()
{
$cate_tree = M("Ask")->findAll();
$this->assign("cate_tree", $cate_tree);
Cookie::set('_currentUrl_', NULL);
parent::edit();
}
示例9: ajaxAddProblemAction
public function ajaxAddProblemAction()
{
$contestId = (int) Request::getPOST('contest-id');
$remote = (int) Request::getPOST('remote');
$problemCode = Request::getPOST('problem-code');
if (!array_key_exists($remote, StatusVars::$REMOTE_SCHOOL) || empty($problemCode) || empty($contestId)) {
$this->renderError('缺少参数!');
}
// 默认题库
Cookie::set('default_remote', $remote);
$contestInfo = OjContestInterface::getDetail(array('id' => $contestId));
if (empty($contestInfo)) {
$this->renderError('竞赛不存在!');
}
$problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
if (empty($problemInfo)) {
$this->renderError('题目不存在!');
}
// 只能添加公开的题目,或者自建私有的题目
if ($problemInfo['hidden'] && $problemInfo['user_id'] != $this->loginUserInfo['id']) {
$this->renderError('权限不足,无法添加该题目!');
}
$globalIds = $contestInfo['global_ids'];
if (in_array($problemInfo['id'], $globalIds)) {
$this->renderError('题目已经添加!');
}
// 题目上限
if (count($globalIds) >= ContestVars::CONTEST_PROBLEM_LIMIT) {
$this->renderError('题目数量达到上限,无法继续添加!');
}
// 更新数据
OjContestInterface::addProblem(array('id' => $contestId, 'remote' => $remote, 'problem_code' => $problemCode));
$this->setNotice(FrameworkVars::NOTICE_SUCCESS, '添加成功!');
$this->renderAjax(0);
}
示例10: _initialize
function _initialize()
{
//先检查cookie
if (!Cookie::is_set($_SESSION['cookietime'])) {
redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
} else {
//保存cookie信息
Cookie::set($_SESSION['cookietime'], '1', 60 * 60 * 3);
}
// 用户权限检查
if (C('USER_AUTH_ON') && !in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE')))) {
import('@.ORG.RBAC');
if (!RBAC::AccessDecision()) {
//检查认证识别号
if (!$_SESSION[C('USER_AUTH_KEY')]) {
//跳转到认证网关
redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
}
// 没有权限 抛出错误
if (C('RBAC_ERROR_PAGE')) {
// 定义权限错误页面
redirect(C('RBAC_ERROR_PAGE'));
} else {
if (C('GUEST_AUTH_ON')) {
$this->assign('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY'));
}
// 提示错误信息
$this->error(L('_VALID_ACCESS_'));
}
}
}
}
示例11: before
public function before()
{
parent::before();
//Visits
$visited = \Cookie::get('visited', false);
if (!$visited) {
\Dashboard::log_visitor();
\Cookie::set("visited", true, time() + 86400);
}
// Cart
\Config::load('cart', true);
$cartManager = new \Cart\Manager(\Config::get('cart'));
\CartManager::init($cartManager);
\CartManager::context('Cart');
// Set Visitors group default
\Product\Model_Attribute::set_user_group(3);
\Theme::instance()->active('frontend');
\Theme::instance()->set_template($this->template);
// Set a global variable so views can use it
$seo = array('meta_title' => '', 'meta_description' => '', 'meta_keywords' => '', 'canonical_links' => '', 'meta_robots_index' => 1, 'meta_robots_follow' => 1);
\View::set_global('seo', $seo, false);
\View::set_global('theme', \Theme::instance(), false);
\View::set_global('logged', $this->check_logged(), false);
\View::set_global('guest', $this->check_guest(), false);
\View::set_global('logged_type', $this->check_logged_type(), false);
}
示例12: _login
public function _login($user, $password, $remember)
{
if (!is_object($user)) {
$username = $user;
// Load the user
$user = Sprig::factory('user', array('login' => $username))->load();
}
if (is_string($password)) {
// Создаем хэш пароя
$password = $this->hash($password);
}
// Проверяем наличие роли Login и соответствие пароля
if ($user->has_role('login') and $user->password === $password) {
// Если выбран чекбокс Запомнить меня
if ($remember === TRUE) {
// Token data
$data = array('user_id' => $user->id, 'expires' => time() + $this->_config['lifetime'], 'user_agent' => sha1(Request::$user_agent));
// Create a new autologin token
$token = Sprig::factory('token')->values($data)->create();
// Set the autologin cookie
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
}
// Finish the login
$this->complete_login($user);
return TRUE;
}
// Login failed
return FALSE;
}
示例13: login
/**
* @fn login
* @short Action method to perform a login.
*/
function login()
{
if ($this->request->is_post()) {
$conn = Db::get_connection();
$user_factory = new User();
$users = $user_factory->find_all(array('where_clause' => "`username` = '{$conn->escape($_POST['username'])}' AND `password` = '" . md5($_POST['password']) . "'", 'limit' => 1));
if (count($users) > 0) {
$user = $users[0];
$expires = $_POST['leave_me_registered'] ? Time::next_year() : Time::tomorrow();
Cookie::set('_u', $user->username, $expires, "/", FALSE);
Cookie::set('_uid', md5(Login::magic_phrase . $user->password), $expires, "/", FALSE);
// Annotates the login in the database
$user_login = new UserLogin();
$user_login->user_id = $user->id;
$user_login->performed_at = date("Y-m-d H:i:s");
$user_login->save();
$this->flash(sprintf(l('Welcome, %s'), $user->first), 'info');
// When login is required to access a particular action, we may store controller & action in a session,
// perform login, then redirect to the action requested in the first place
if (isset($_SESSION['redirect_to'])) {
$this->redirect_to(array('controller' => $_SESSION['redirect_to']['controller'], 'action' => $_SESSION['redirect_to']['action']));
} else {
$this->redirect_to(array('controller' => 'home'));
}
Db::close_connection($conn);
} else {
$this->flash(l('Bad username / password'), 'error');
}
}
$this->redirect_to(array('action' => 'index'));
}
示例14: _list
protected function _list($model, $map, $sortBy = '', $asc = false)
{
//取得满足条件的记录数
$count = $model->table(array('tb_press_numinfo' => 'press_numinfo'))->join('tb_magazine magazine on magazine.postCode = press_numinfo.postCode')->join('tb_magazine_terrm magazine_terrm on magazine_terrm.id = press_numinfo.termID')->join('tb_employee_newspaper employee_newspaper on magazine.postcode = employee_newspaper.postcode')->where($map)->count('press_numinfo.id');
if ($count > 0) {
import("ORG.Util.Page");
//创建分页对象
if (!empty($_REQUEST['listRows'])) {
$listRows = $_REQUEST['listRows'];
} else {
$listRows = '';
}
$p = new Page($count, $listRows);
//分页查询数据
$fieldStr = 'press_numinfo.id as id, magazine.name as magazineName, magazine_terrm.name as magazineTerrmName, magazine_terrm.month as month, magazine_terrm.year as year, press_numinfo.printNum as printNum';
$orderStr = 'magazine_terrm.year asc, magazine_terrm.month asc, magazine_terrm.id asc';
$voList = $model->table(array('tb_press_numinfo' => 'press_numinfo'))->join('tb_magazine magazine on magazine.postCode = press_numinfo.postCode')->join('tb_magazine_terrm magazine_terrm on magazine_terrm.id = press_numinfo.termID')->join('tb_employee_newspaper employee_newspaper on magazine.postcode = employee_newspaper.postcode')->where($map)->order($orderStr)->limit($p->firstRow . ',' . $p->listRows)->field($fieldStr)->select();
//分页显示
$page = $p->show();
//模板赋值显示
$this->assign('list', $voList);
$this->assign("page", $page);
}
$this->assign('totalCount', $count);
$this->assign('numPerPage', C('PAGE_LISTROWS'));
$this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1);
Cookie::set('_currentUrl_', __SELF__);
return;
}
示例15: checklogin
public function checklogin()
{
$userEmail = isset($_POST["email"]) ? $_POST["email"] : Cookie::get("email");
$userPassword = isset($_POST["password"]) ? md5($_POST["password"]) : Cookie::get("password");
//验证用户信息
$userDao = D('User');
$user = $userDao->find("email='{$userEmail}' and password='{$userPassword}'", 'id,name,email,sex');
//验证成功
if ($user) {
//更新登录时间
$userDao->setField('lastLoginTime', time(), "id=" . $user->id);
//D('Login')->add("userId='$user->id'");
//记录登陆状态
Session::set('mid', $user->id);
Session::set('userInfo', $user);
Cookie::set('email', $userEmail, 36000000);
//记住登录
if ($_POST["autologin"] == 'on') {
Cookie::set("password", $userPassword, 36000000);
}
unset($userEmail, $userPassword);
//跳转到Home页
$this->redirect('index', 'Home');
//验证失败
} else {
//跳转到登陆页面
$this->redirect("login");
}
}