本文整理汇总了PHP中cookie函数的典型用法代码示例。如果您正苦于以下问题:PHP cookie函数的具体用法?PHP cookie怎么用?PHP cookie使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cookie函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
if ($_GET['source'] && !cookie('source')) {
cookie('source', trim($_GET['source']));
}
if (isset($_GET['spm']) && $_GET['spm']) {
cookie('_spm', $_GET['spm'], array('expire' => 172800, 'domain' => '.wdwd.com', 'path' => '/'));
}
if (!session('?shop')) {
$this->redirect('admin/passport/logout');
}
/*
var_dump(session('shop'));
exit;
if (!session('?shop') || ('' == session('shop.mobile'))) {
if (session('?user')) {
$this->redirect('admin/passport/bind');
}
else {
$this->redirect('admin/passport/logout');
}
}
*/
$shop = session('shop');
$shop['decode_shop_id'] = \Common\Lib\Idhandler::decode($shop['shop_id']);
$this->passport = session('passport');
$this->shop = $shop;
$this->shop['mobile'] = $this->passport['loginname'];
//print_r($this->shop);
//print_r(session('passport'));
parent::__construct();
}
示例2: receiveEvent
private function receiveEvent($object)
{
$contentStr = "";
switch ($object->Event) {
case "subscribe":
$contentStr = "欢迎关注方倍工作室";
cookie('openid', $object->FromUserName . '');
break;
case "unsubscribe":
$contentStr = "";
break;
case "CLICK":
switch ($object->EventKey) {
case "天气北京":
$contentStr = "北京天气晴!";
break;
default:
$contentStr = "你点击了菜单: " . $object->EventKey;
break;
}
break;
default:
$contentStr = "receive a new event: " . $object->Event;
break;
}
$resultStr = $this->transmitText($object, $contentStr);
return $resultStr;
}
示例3: rememberMe
public function rememberMe($userId, $password, $expire = 864000)
{
$token['userId'] = $userId;
$token['verify'] = sha1(md5($password));
cookie('token', $token, $expire);
return 1;
}
开发者ID:AlexanderFeng,项目名称:a-simple-question-and-answer-website,代码行数:7,代码来源:AutoLoginController.class.php
示例4: dealData
public function dealData()
{
$username = I('username', null, 'htmlspecialchars');
$password = I('password', null, 'htmlspecialchars');
$remember = I('checkbox', 0, 'htmlspecialchars');
if ($username != null && $password != null) {
$data = M()->table('Admin')->where(array('username' => $username))->find();
if ($data['username'] == $username && $data['password'] == md5($password)) {
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['remember'] = $remember;
M()->table('Admin')->where('id=1')->setField('logintime', time());
if ($remember == 1) {
cookie('remember', $username . ":" . $password, time() + 3600 * 24);
}
$this->redirect("Index/index", array("tab" => 1));
} else {
echo "<script> alert('用户名或密码错误!');parent.location.href='index.html'; </script>";
exit;
}
} else {
if ($username == null) {
echo "<script> alert('用户名不能为空!');parent.location.href='index.html'; </script>";
exit;
} else {
if ($password == null) {
echo "<script> alert('密码不能为空!');parent.location.href='index.html'; </script>";
exit;
}
}
}
}
示例5: edit
public function edit($id)
{
//get提交时 根据id查询出相应的数据进行回显
if (IS_GET) {
$rows = $this->model->find($id);
//查询一条数据用find
//分配数据到页面
$this->assign($rows);
$this->_edit_view_before();
$this->assign("meta_title", "编辑{$this->meta_title}");
//调用显示页面
$this->display("edit");
} else {
//post提交时用create方法收集数据,并用save方法更新到数据库涨
if ($this->model->create() !== false) {
//有数据时进行更新操作
if ($this->model->save($this->usePostParams ? I('post.') : '') !== false) {
//更新成功时跳转到cookie中保存的当前页面
$this->success("更新成功...", cookie("__nowurl__"));
return;
}
$this->error("更新失败.." . show_model_error($this->model));
}
}
}
示例6: getBrands
/**
* 列表查询
*/
public function getBrands()
{
$m = D('Home/Brands');
$brandslist = $m->queryBrandsByDistrict();
cookie("bstreesAreaId3", I("areaId3"));
$this->ajaxReturn($brandslist);
}
示例7: loginCheck
/**
* 登录验证
*/
public function loginCheck()
{
$name = $this->_post('name');
$password = $this->_post('password');
$user = M('user');
$condition['name'] = $name;
$data = $user->where($condition)->select();
if ($data) {
if ($data[0]['password'] == $password) {
//验证成功
session('user_id', $data[0]['id']);
cookie('user_id', $data[0]['id'], 3600);
//$this->display('Home:hometest');
//$this->display('Home:home');
header('location:' . $this->conf['APP_ROOT'] . 'Home/home');
} else {
//密码错误
$message = '对不起,您的密码错误!';
$this->assign('message', $message);
$this->display('Login:loginFail');
}
} else {
//用户名不存在
$message = '对不起,用户名不存在!';
$this->assign('message', $message);
$this->display('Login:loginFail');
}
}
示例8: _initialize
public function _initialize()
{
if (!session("user_id")) {
if (!cookie("user_id")) {
$user_id = D("User")->user_add();
cookie("user_id", $user_id, 36000000);
cookie("token", md5(C("cookie_key") . $user_id), 36000000);
session("user_id", $user_id);
} else {
$user_id = cookie("user_id");
$token = cookie("token");
if (md5(C("cookie_key") . $user_id) == $token) {
session("user_id", $user_id);
cookie("user_id", $user_id, 36000000);
cookie("token", md5(C("cookie_key") . $user_id), 36000000);
} else {
$user_id = D("User")->user_add();
cookie("user_id", $user_id, 36000000);
cookie("token", md5(C("cookie_key") . $user_id), 36000000);
session("user_id", $user_id);
}
}
} else {
$user_id = session("user_id");
}
$user = D("user")->getuser($user_id);
define('UID', $user_id);
define('NAME', $user['name']);
}
示例9: edit
/**
* 修改菜单
*/
public function edit($id)
{
$model = D('Menu');
if (IS_POST) {
if ($model->create()) {
if ($model->updateMenu() !== false) {
$this->success('修改成功', cookie('forward'));
} else {
$this->error('修改失败');
}
} else {
$this->error(get_errors($model->getError()));
}
} else {
//1.根据id获取数据表中的数据
//获取所有的菜单
$this->assign('all_menu', $model->getList(array('id,name,parent_id'), array(), true));
//获取所有的权限
//取出所有的权限
$this->assign('all_permissions', D('Permission')->getList('id,name,parent_id', array(), true));
//获取当前关联的权限
$this->assign('perms', $model->getPermission($id, true));
$row = $model->find($id);
$this->assign('row', $row);
$this->display();
}
}
示例10: logout
public function logout()
{
session('user_status', NULL);
cookie('token', NULL);
cookie('username', NULL);
cookie('userid', NULL);
}
示例11: logout
public function logout()
{
cookie('suid', null);
session('user', null);
session('login', null);
header('Location: ' . __SHOP__);
}
示例12: logout
/**
* 退出
*/
public function logout()
{
session_regenerate_id();
session(null);
cookie(null);
redirect(U('Login/index'));
}
示例13: flow2
public function flow2()
{
if (!is_login()) {
cookie('__forward__', __SELF__);
$this->error('请先登录', U('Member/login'));
return;
}
if (IS_POST) {
$order_model = D('OrderInfo');
if ($order_model->addOrder()) {
$this->redirect('flow3');
} else {
$this->error('下单失败,请稍后再试');
}
} else {
//用户地址列表
$this->assign('address_list', D('Address')->getAddList());
//获取支付方式
$this->assign('pay_list', D('Setting')->getPayList());
//获取配送方式
$this->assign('transport_list', D('Setting')->getTransportList());
//取出购物车里面的内容
$this->assign('car_list', D('ShoppingCar')->getCar());
$this->display();
}
}
示例14: searchArticle
/**
* [searchArticle 搜索文章]
* @Author 罗江涛
* @DateTime 2016-03-07T17:03:47+0800
*/
public function searchArticle()
{
// 接收关键字
$keyword = I("keyword", 0);
// 是否清除搜索历史
$cleanSearchHistory = I("cleanSearchHistory", 0);
// 清除搜索历史
if ($cleanSearchHistory) {
cookie("searchHistory", null);
}
// 获取搜索历史
$searchHistory = cookie("searchHistory");
if ($keyword) {
// 如果有关键字则保存到搜索历史
if (!in_array($keyword, $searchHistory) && $keyword != "{{ todo.logo }}") {
$searchHistory[] = $keyword;
//p($searchHistory);die;
cookie("searchHistory", $searchHistory);
}
} else {
// 没有关键字倒序搜索历史,并分配
$searchHistory = array_reverse($searchHistory);
$this->assign("searchHistory", $searchHistory);
}
$this->display();
}
示例15: _initialize
protected function _initialize()
{
$this->_name = CONTROLLER_NAME;
if (isLogin()) {
define('AID', isLogin());
$this->uid = decrypt(cookie('admin_id'));
$this->admin_name = decrypt(cookie('admin_name'));
$this->assign('admin_name', $this->admin_name);
} else {
$this->redirect('Public/login');
exit;
}
import('ORG.Util.Auth');
//加载类库
$auth = new Auth();
if (in_array(isLogin(), C("ADMINISTRATOR"))) {
return true;
} else {
if ($auth->check(CONTROLLER_NAME . '-*', isLogin())) {
true;
} elseif (!$auth->check(CONTROLLER_NAME . '-' . ACTION_NAME, isLogin())) {
echo CONTROLLER_NAME . '-' . ACTION_NAME;
die;
$this->error('你没有权限');
}
}
}