public function start() { if ($this->isStarted()) { return; } $id = $this->request->getCookie(self::SESSION_NAME); if (!$this->storage->hasSession($id)) { $id = $this->storage->createSession(); $this->response->setCookie(self::SESSION_NAME, $id, array('Path' => '/')); } $this->id = $id; }
/** * 登录跳转助手 * @author limingyou */ public static function isLogin() { /*获取登录用户信息*/ if (Request::getCookie('_ido_uid', 0, 'int')) { return true; } return false; }
/** * 判断用户是否登录并返回用户cookie中的基本信息 */ public static function getUserCookieInfo() { $isLogin = Util::isLogin(); $userInfo = array(); if ($isLogin) { $userInfo['userid'] = $userInfo['uid'] = intval(Request::getCookie('_ido_uid', 0, 'int')); $userInfo['username'] = Request::getCookie('_ido_username'); } return $userInfo; }
/** * @descrpition 后台管理权限 * @return array */ public static function getUserAuths() { $uid = Request::getCookie('admin_uid'); $gid = Request::getCookie('admin_gid'); if ($gid == 1) { return array(); } $adminObj = new AdminModel(); $adminInfo = $adminObj->getAdminOne($uid); $isExtends = empty($adminInfo['is_extends_priv']) ? 0 : 1; $auths = $adminAuths = $groupAuths = array(); $adminprivObj = new AdminprivModel(); $adminAuths = $adminprivObj->getAdminpriv($uid); $auths = empty($adminAuths) ? $auths : array_merge($auths, $adminAuths); if ($isExtends) { $groupprivObj = new GroupprivModel(); $groupAuths = $groupprivObj->getGrouppriv($gid); $auths = empty($groupAuths) ? $auths : array_merge($auths, $groupAuths); } return $auths; }
public function testGetCookie() { $this->assertThat($this->object->getCookie('user'), $this->equalTo('123')); $this->assertThat($this->object->getCookie('undefined', 'default'), $this->equalTo('default')); $this->assertThat($this->object->getCookie('undefined'), $this->equalTo(null)); }
/** * Description: 评分 */ public function score() { $articleId = Request::getRequest('article_id', 'int', 58); $score = Request::getRequest('score', 'int', 1); //判断参数 if ($score != 1 && $score != 2) { View::showErrorMessage(GAME_URL, '非法操作'); } //返回 $data = array(); //判断是否24小时内已经投过了。cookie判断,伪验证。 $addScore = Request::getCookie('add_score'); if (!empty($addScore) && $addScore - time() <= 86400) { $data['status'] = -2; $data['msg'] = '<p class="text-center">说你呢-.-</p><p class="text-center">不要贪得无厌哦</p><p class="text-center">24小时内只能顶一次'; return json_encode($data); } Response::setCookie('add_score', time(), time() + 86400); //更新数据库 if ($score == 1) { $result = ArticleBusiness::goodNum($articleId); } else { if ($score == 2) { $result = ArticleBusiness::badNum($articleId); } } //整理返回值 if ($result) { $data['status'] = 0; $data['msg'] = 1; } else { $data['status'] = -1; $data['msg'] = '不明所以的失败了,请重新。'; } return json_encode($data); }