當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。