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


PHP zmf::setCookie方法代码示例

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


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

示例1: _referer

 function _referer()
 {
     $currentUrl = Yii::app()->request->url;
     $arr = array('/site/', '/error/', '/attachments/');
     $set = true;
     if (Common::checkImg($currentUrl)) {
         $set = false;
     }
     if ($set) {
         foreach ($arr as $val) {
             if (!$set) {
                 break;
             }
             if (strpos($currentUrl, $val) !== false) {
                 $set = false;
                 break;
             }
         }
     }
     if ($set && Yii::app()->request->isAjaxRequest) {
         $set = false;
     }
     $referer = zmf::getCookie('refererUrl');
     if ($set) {
         zmf::setCookie('refererUrl', $currentUrl, 86400);
     }
     if ($referer != '') {
         $this->referer = $referer;
     }
 }
开发者ID:ph7pal,项目名称:mei,代码行数:30,代码来源:Q.php

示例2: beforeSave

 public function beforeSave()
 {
     $ip = Yii::app()->request->userHostAddress;
     $key = 'ipInfo-' . $ip;
     $ipData = zmf::getCookie($key);
     if (!$ipData) {
         $url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip=' . $ip;
         // 执行HTTP请求
         $header = array('apikey:e5882e7ac4b03c5d6f332b6de4469e81');
         $ch = curl_init();
         // 添加apikey到header
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_URL, $url);
         $res = curl_exec($ch);
         $res = CJSON::decode($res, true);
         $retData = array();
         if ($res['errNum'] == 0) {
             $retData = $res['retData'];
         }
         $ipData = json_encode($retData);
         zmf::setCookie($key, $ipData, 2592000);
     }
     $this->ip = ip2long($ip);
     $this->ipInfo = $ipData;
     return true;
 }
开发者ID:ph7pal,项目名称:momo,代码行数:27,代码来源:Comments.php

示例3: actionLogin

 function actionLogin()
 {
     $this->layout = 'common';
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作', Yii::app()->createUrl('admin/index/index'));
     }
     $model = new LoginForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate() && $model->login()) {
             $arr = array('latestLoginTime' => zmf::now());
             $uid = Yii::app()->user->id;
             if (!$this->checkPower('user', $uid, true)) {
                 Yii::app()->user->logout();
                 $model->addError('username', '您不是管理员');
             } else {
                 //User::model()->updateByPk($uid, $arr);
                 zmf::delCookie('checkWithCaptcha');
                 //只允许单点登录
                 $randKey = zmf::randMykeys(8);
                 zmf::setCookie('adminRandKey' . $uid, $randKey, 86400);
                 zmf::setFCache('adminRandKey' . $uid, $randKey, 86400);
                 //记录操作
                 //UserLog::add($uid, '登录后台'.Yii::app()->request->userHostAddress);
                 $uuid = zmf::uuid();
                 zmf::setCookie('userCheckedLogin' . $uid, $uuid, 86400);
                 $this->redirect(array('index/index'));
             }
         } else {
             $times = zmf::getCookie('checkWithCaptcha');
             zmf::setCookie('checkWithCaptcha', intval($times) + 1, 86400);
         }
     }
     $data = array('model' => $model);
     $this->render('login', $data);
 }
开发者ID:ph7pal,项目名称:momo,代码行数:40,代码来源:SiteController.php

示例4: actionLogin

 public function actionLogin()
 {
     $this->onlyOnPc();
     $this->layout = 'common';
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作');
     }
     $canLogin = true;
     $ip = Yii::app()->request->getUserHostAddress();
     $cacheKey = 'loginErrors-' . $ip;
     $errorTimes = zmf::getFCache($cacheKey);
     if ($errorTimes >= 5) {
         $canLogin = false;
     }
     if ($canLogin) {
         $model = new FrontLogin();
         if (isset($_POST['FrontLogin'])) {
             $model->attributes = $_POST['FrontLogin'];
             if ($model->validate() && $model->login()) {
                 $arr = array('latestLoginTime' => zmf::now());
                 $uid = Yii::app()->user->id;
                 //                    User::model()->updateByPk($uid, $arr);
                 zmf::delCookie('checkWithCaptcha');
                 zmf::delFCache($cacheKey);
                 if ($this->referer) {
                     $this->redirect($this->referer);
                 } else {
                     $this->redirect(zmf::config('baseurl'));
                 }
             } else {
                 zmf::updateFCacheCounter($cacheKey, 1, 3600);
                 zmf::setCookie('checkWithCaptcha', 1, 86400);
             }
         }
     }
     $this->pageTitle = '登录';
     $this->render('login', array('model' => $model));
 }
开发者ID:ph7pal,项目名称:momo,代码行数:38,代码来源:SiteController.php

示例5: actionLogin

 public function actionLogin($from = '')
 {
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作');
     }
     $model = new LoginForm();
     //登录
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'users-addUser-form') {
         echo CActiveForm::validate($modelUser);
         Yii::app()->end();
     }
     //登录
     if (isset($_POST['LoginForm'])) {
         $from = 'login';
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate()) {
             if ($model->login()) {
                 $arr = array('last_login_ip' => ip2long(Yii::app()->request->userHostAddress), 'last_login_time' => zmf::now());
                 Users::model()->updateByPk(Yii::app()->user->id, $arr);
                 Users::model()->updateCounters(array('login_count' => 1), ':id=id', array(':id' => Yii::app()->user->id));
                 if ($this->referer == '') {
                     $this->referer = array('users/index');
                 }
                 zmf::delCookie('checkWithCaptcha');
                 $this->redirect($this->referer);
             }
         } else {
             zmf::setCookie('checkWithCaptcha', 1, 86400);
         }
     }
     $this->pageTitle = '登录 - ' . zmf::config('sitename');
     $this->render('login', array('model' => $model));
 }
开发者ID:ph7pal,项目名称:mei,代码行数:37,代码来源:SiteController.php

示例6: actionLimit

 /**
  * 限制用户对某一操作的频率,如点赞,收藏,关注
  * 默认4次
  */
 public static function actionLimit($type, $keyid, $num = 4)
 {
     $cacheKey = 'actionLimit-' . $type . '-' . $keyid;
     $info = (int) zmf::getCookie($cacheKey);
     if ($info >= $num) {
         return true;
     } else {
         zmf::setCookie($cacheKey, $info + 1, 60);
         return false;
     }
 }
开发者ID:ph7pal,项目名称:mei,代码行数:15,代码来源:zmf.php

示例7: actionAddComment

 public function actionAddComment()
 {
     $keyid = zmf::val('k', 2);
     $to = zmf::val('to', 2);
     $type = zmf::val('t', 1);
     $content = zmf::val('c', 1);
     $email = zmf::val('email', 1);
     $username = zmf::val('username', 1);
     if (!isset($type) or !in_array($type, array('posts'))) {
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     if (!isset($keyid) or !is_numeric($keyid)) {
         $this->jsonOutPut(0, Yii::t('default', 'pagenotexists'));
     }
     if (!$content) {
         $this->jsonOutPut(0, '评论不能为空哦~');
     }
     if ($this->uid) {
         $status = Posts::STATUS_PASSED;
         $uid = $this->uid;
     } else {
         if (!$username) {
             $this->jsonOutPut(0, '请填写称呼');
         }
         zmf::setCookie('noLoginUsername', $username, 2592000);
         if ($email != '') {
             $validator = new CEmailValidator();
             if (!$validator->validateValue($email)) {
                 $this->jsonOutPut(0, '请填写正确的邮箱地址');
             }
             zmf::setCookie('noLoginEmail', $email, 2592000);
         }
         $status = Posts::STATUS_STAYCHECK;
         $uid = 0;
         if (zmf::actionLimit($type, $keyid, 5, 86400, true)) {
             $this->jsonOutPut(0, '操作太频繁,请稍后再试');
         }
     }
     $postInfo = Posts::model()->findByPk($keyid);
     if (!$postInfo || $postInfo['status'] != Posts::STATUS_PASSED) {
         $this->jsonOutPut(0, '您所评论的内容不存在');
     }
     //处理文本
     $filter = Posts::handleContent($content);
     $content = $filter['content'];
     $model = new Comments();
     $toNotice = true;
     $touid = $postInfo['uid'];
     if ($to) {
         $comInfo = Comments::model()->findByPk($to);
         if (!$comInfo || $comInfo['status'] != Posts::STATUS_PASSED) {
             $to = '';
         } elseif ($comInfo['uid'] == $uid) {
             $toNotice = false;
         } else {
             $touid = $comInfo['uid'] > 0 ? $comInfo['uid'] : '';
             $toNotice = true;
         }
     }
     $intoData = array('logid' => $keyid, 'uid' => $uid, 'content' => $content, 'cTime' => zmf::now(), 'classify' => $type, 'platform' => '', 'tocommentid' => $to, 'status' => $status, 'username' => $username, 'email' => $email);
     unset(Yii::app()->session['checkHasBadword']);
     $model->attributes = $intoData;
     if ($model->validate()) {
         if ($model->save()) {
             if ($type == 'posts') {
                 $_url = CHtml::link('查看详情', array('posts/view', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 if ($status == Posts::STATUS_PASSED) {
                     Posts::updateCommentsNum($keyid);
                 }
                 $_content = '您的文章有了新的评论,' . $_url;
             }
             if ($to && $_url) {
                 $_content = '您的评论有了新的回复,' . $_url;
             }
             if ($toNotice) {
                 $_noticedata = array('uid' => $touid, 'authorid' => $uid, 'content' => $_content, 'new' => 1, 'type' => 'comment', 'cTime' => zmf::now(), 'from_id' => $model->id, 'from_num' => 1);
                 Notification::add($_noticedata);
             }
             if ($uid) {
                 $intoData['loginUsername'] = $this->userInfo['truename'];
             }
             $html = $this->renderPartial('/posts/_comment', array('data' => $intoData, 'postInfo' => $postInfo), true);
             $this->jsonOutPut(1, $html);
         } else {
             $this->jsonOutPut(0, '新增评论失败');
         }
     } else {
         $this->jsonOutPut(0, '新增评论失败');
     }
 }
开发者ID:ph7pal,项目名称:momo,代码行数:90,代码来源:AjaxController.php

示例8: actionLogin


//.........这里部分代码省略.........
                     $user = Users::model()->find('email=:email', array(':email' => $email));
                 } else {
                     $user = Users::model()->find('truename=:truename', array(':truename' => $email));
                 }
                 if ($user) {
                     $bindInfo = UserWeixin::model()->findByPk($user['id']);
                     if ($bindInfo) {
                         $hasBind = true;
                     }
                     $binddata['uid'] = $user['id'];
                 }
             }
             if ($hasBind) {
                 $model->addError('email', '该账号已绑定其他账号');
             } elseif ($model->login()) {
                 $arr = array('last_login_ip' => ip2long(Yii::app()->request->userHostAddress), 'last_login_time' => time());
                 Users::model()->updateByPk(Yii::app()->user->id, $arr);
                 Users::model()->updateCounters(array('login_count' => 1), ':id=id', array(':id' => Yii::app()->user->id));
                 if ($this->referer == '') {
                     $this->referer = array('users/index', 'id' => Yii::app()->user->id);
                 }
                 zmf::delCookie('checkWithCaptcha');
                 //微博绑定已有账号
                 if ($bind == 'weibo') {
                     UserSina::addCookie($binddata);
                 } elseif ($bind == 'qq') {
                     UserQq::addCookie($binddata);
                 } elseif ($bind == 'weixin') {
                     UserWeixin::addCookie($binddata);
                 }
                 $this->redirect($this->referer);
             }
         } else {
             zmf::setCookie('checkWithCaptcha', 1, 86400);
         }
     } elseif (isset($_POST['Users'])) {
         $from = 'reg';
         //注册
         if (UserAction::checkRegTimes()) {
             $this->message(0, '您今天的注册次数已用完');
         }
         $email = zmf::filterInput($_POST['Users']['email'], 't', 1);
         $truename = zmf::filterInput($_POST['Users']['truename'], 't', 1);
         $inputData = array('truename' => $truename, 'password' => $_POST['Users']['password'] != '' ? md5($_POST['Users']['password']) : '', 'email' => $email, 'cTime' => time(), 'register_time' => time(), 'last_login_time' => time(), 'groupid' => zmf::config('userDefaultGroup'), 'register_ip' => ip2long(Yii::app()->request->userHostAddress), 'last_login_ip' => ip2long(Yii::app()->request->userHostAddress));
         $modelUser->attributes = $inputData;
         if ($modelUser->validate()) {
             if ($modelUser->save()) {
                 $_model = new LoginForm();
                 $_model->email = $email;
                 $_model->password = $_POST['Users']['password'];
                 $_model->login();
                 if ($bind == 'weibo') {
                     $strdata = zmf::getCookie('userWeiboData');
                     //取出cookie中用户的微博信息
                     if ($strdata) {
                         $binddata = unserialize($strdata);
                         $binddata['uid'] = Yii::app()->user->id;
                         UserSina::addCookie($binddata);
                     }
                 } elseif ($bind == 'qq') {
                     $strdata = zmf::getCookie('userQQData');
                     //取出cookie中用户的微博信息
                     if ($strdata) {
                         $binddata = unserialize($strdata);
                         $binddata['uid'] = Yii::app()->user->id;
                         UserQq::addCookie($binddata);
开发者ID:ph7pal,项目名称:wedding,代码行数:67,代码来源:SiteController.php

示例9: actionCallback

 public function actionCallback()
 {
     $cacheToken = zmf::getCookie('weibojs_' . $this->weiboService->client_id);
     //将token存入cookie,方便下次调用
     if (isset($_REQUEST['code']) && !$cacheToken) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = $this->WB_CALLBACK_URL;
         try {
             $token = $this->weiboService->getAccessToken('code', $keys);
             zmf::setCookie('weibojs_' . $this->weiboService->client_id, serialize($token), $this->cookieTime);
         } catch (OAuthException $e) {
             $this->message(0, '获取授权信息出错,请重试');
         }
     } elseif ($cacheToken) {
         $token = unserialize($cacheToken);
     }
     if (!$token || !$token['access_token']) {
         $this->message(0, '获取授权信息出错,请重试');
     }
     //根据ID获取用户等基本信息
     $c = new SaeTClientV2($this->WB_AKEY, $this->WB_SKEY, $token['access_token']);
     $uid_get = $c->get_uid();
     $sinauid = $uid_get['uid'];
     //新浪的用户ID
     $user_message = $c->show_user_by_id($sinauid);
     if (!$user_message) {
         $this->message(0, '获取用户信息出错,请重试');
     }
     //将用户数据存入cookie
     $data['access_token'] = $token['access_token'];
     $data['expires_in'] = zmf::now() + intval($token['expires_in']);
     $data['sinauid'] = $sinauid;
     $data['screen_name'] = $user_message['screen_name'];
     $data['name'] = $user_message['name'];
     $data['profile_url'] = 'http://weibo.com/' . $user_message['profile_url'];
     $data['avatarurl'] = $user_message['avatar_hd'];
     $infoArr = array('screen_name' => $user_message['screen_name'], 'avatarurl' => $user_message['avatarurl'], 'profile_url' => 'http://weibo.com/' . $user_message['profile_url']);
     $data['data'] = serialize($infoArr);
     $strdata = serialize($data);
     zmf::setCookie('userWeiboData', $strdata, $this->cookieTime);
     //获取用户之前的意图,是注册、登录还是绑定
     $action = zmf::getCookie('lastWeiboAction');
     if (!in_array($action, array('login', 'reg', 'bind'))) {
         throw new CHttpException(403, '缺少参数');
     }
     if (in_array($action, array('login', 'reg')) && zmf::uid()) {
         $this->message(0, '您已登录,请勿该操作', $this->referer);
     } elseif ($action == 'bind' && !zmf::uid()) {
         $this->redirect(array('site/login'));
     }
     $bindInfo = UserSina::model()->find('openid=:sinauid', array(':sinauid' => $data['sinauid']));
     if ($action == 'login') {
         //确实绑定过微博,则直接登录
         if ($bindInfo) {
             $this->loginWithWeibo($bindInfo, $data);
         } else {
             //没有绑定过就跳转到注册页面
             $this->redirect(array('site/reg', 'bind' => 'weibo'));
         }
     } elseif ($action == 'reg') {
         //绑定过微博就直接登录
         if ($bindInfo) {
             $this->loginWithWeibo($bindInfo, $data);
         } else {
             //没有绑定过就跳转到注册页面
             $this->redirect(array('site/reg', 'bind' => 'weibo'));
         }
     } elseif ($action == 'bind') {
         $uid = zmf::uid();
         if ($bindInfo) {
             throw new CHttpException(403, '该微博已经绑定其他账户');
         } else {
             $otherBind = UserSina::model()->findByPk($uid);
             if ($otherBind) {
                 throw new CHttpException(403, '您已经绑定过其他账户');
             }
             $data['uid'] = $uid;
             if (UserSina::addCookie($data)) {
                 //返回设置页面
                 $this->redirect(array('users/config'));
             } else {
                 throw new CHttpException(403, '写入数据时错误,请重试');
             }
         }
     }
 }
开发者ID:ph7pal,项目名称:wedding,代码行数:87,代码来源:WeiboController.php

示例10: likeAreaByCookie

 private function likeAreaByCookie($keyid)
 {
     $cacheKey = 'myLikeAreas';
     $info = zmf::getCookie($cacheKey);
     if (!$info) {
         $arr[] = $keyid;
     } else {
         $tmp = explode(',', $info);
         if (empty($tmp)) {
             $arr[] = $keyid;
         } else {
             $find = false;
             foreach ($tmp as $k => $v) {
                 if ($v == $keyid) {
                     $find = true;
                     unset($tmp[$k]);
                     break;
                 }
             }
             if (!$find) {
                 $arr = $tmp;
                 $arr[] = $keyid;
             } else {
                 $arr = $tmp;
             }
         }
     }
     $value = join(',', $arr);
     zmf::setCookie($cacheKey, $value, 31536000);
     //存一年
     if (!$find) {
         $this->jsonOutPut(1, '添加收藏成功' . $value);
     } else {
         $this->jsonOutPut(3, '取消收藏成功' . $value);
     }
 }
开发者ID:ph7pal,项目名称:wedding,代码行数:36,代码来源:AjaxController.php


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