• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Cookie类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: md5

 function &createSession($create = TRUE)
 {
     if (ServletContext::validClass($this->context)) {
         $response =& $this->context->getServletResponse();
         $session =& $this->context->getServletSession();
         if (IHttpResponse::validClass($response) && IHttpSession::validClass($session)) {
             $sessionid = '';
             $cookie = $this->getCookie('_JPHPSESSIONID');
             if (!isset($cookie)) {
                 $sessionid = $this->getParameter('_JPHPSESSIONID');
             } else {
                 $sessionid = $cookie->getValue();
             }
             if (strlen(trim($sessionid)) < 8) {
                 if ($create == FALSE) {
                     return NULL;
                 } else {
                     $sessionid = md5(StringBuffer::generateKey(16));
                 }
             }
             $session->setSessionID($sessionid);
             $session->initialize();
             $cookie = new Cookie('_JPHPSESSIONID', $sessionid);
             if ($session->getMaxInactiveInterval() > 0) {
                 $cookie->setMaxAge(time() + $session->getMaxInactiveInterval());
             } else {
                 $cookie->setMaxAge(0);
             }
             $response->addCookie($cookie);
             return $session;
         }
     }
     return NULL;
 }
开发者ID:alexpagnoni,项目名称:jphp,代码行数:34,代码来源:HttpServletRequest.php


示例2: process

 function process()
 {
     $siteAdmin = $this->needASiteAdminSelected();
     if ($siteAdmin) {
         $choice = $this->request->getConfirmedState();
         $cookieSet = false;
         // is the cookie already set or not?
         if (isset($_COOKIE[COOKIE_NAME_NO_STAT . $siteAdmin])) {
             $cookieSet = true;
         }
         if ($choice == 1) {
             $ck = new Cookie(COOKIE_NAME_NO_STAT . $siteAdmin);
             if ($cookieSet) {
                 $ck->delete();
             } else {
                 $ck->save();
             }
             $this->setMessage();
         } else {
             if ($cookieSet) {
                 $this->tpl->assign("cookie_no_stat", true);
             } else {
                 $this->tpl->assign("cookie_no_stat", false);
             }
         }
     }
 }
开发者ID:ber5ien,项目名称:www.jade-palace.co.uk,代码行数:27,代码来源:AdminSiteCookieExclude.class.php


示例3: init

 function init($request)
 {
     parent::init($request);
     $ck = new Cookie(COOKIE_NAME_SESSION);
     $ck->delete();
     Request::redirectToModule('index');
 }
开发者ID:ber5ien,项目名称:www.jade-palace.co.uk,代码行数:7,代码来源:Logout.class.php


示例4: Cookie

 /**
  * Creates a cookie object, adds it to the cookies stack and returns an reference to this cookie
  *
  * @param string $name
  *            Name of cookie to create
  *
  * @return \Core\Http\Cookie\CookieInterface
  */
 public function &createCookie(string $name)
 {
     $cookie = new Cookie();
     $cookie->setName($name);
     $this->addCookie($cookie);
     return $cookie;
 }
开发者ID:tekkla,项目名称:core-http,代码行数:15,代码来源:CookieHandler.php


示例5: addCookie

 /**
  * @see CookieManager::addCookie()
  */
 public function addCookie(Cookie $cookie)
 {
     $cookieDomain = $cookie->getDomain();
     if (!isset($this->cookies[$cookieDomain])) {
         $this->cookies[$cookieDomain] = array();
     }
     $this->cookies[$cookieDomain][] = $cookie;
 }
开发者ID:imastersdev,项目名称:correios,代码行数:11,代码来源:HTTPCookieManager.php


示例6: header

 public function header()
 {
     $_cookie = new Cookie('user');
     if ($_cookie->getCookie()) {
         echo "function getHeader() {document.write('{$_cookie->getCookie()}, Hi! <a href=\"register.php?action=logout\">Logout</a>');}";
     } else {
         echo "function getHeader() {document.write('<a href=\"register.php?action=reg\" class=\"user\">Register</a><a href=\"register.php?action=login\" class=\"user\">Login</a>');}";
     }
 }
开发者ID:e0zhao02,项目名称:sample_code,代码行数:9,代码来源:Cache.class.php


示例7: retrieve

 public function retrieve($uuid, $hashed_password, $hmac_hash, $expiration)
 {
     $cookie = new Cookie();
     $cookie->set_uuid($uuid);
     $cookie->set_password($hashed_password);
     $cookie->set_hmac_hash($hmac_hash);
     $cookie->expiration = $expiration;
     return $cookie;
 }
开发者ID:newmight2015,项目名称:csc235_project1,代码行数:9,代码来源:Cookie.php


示例8: header

 public function header()
 {
     $_cookie = new Cookie('user');
     if ($_cookie->getCookie()) {
         echo "function getHeader() {\n\t\t\t\t\tdocument.write('{$_cookie->getCookie()},您好! <a href=\"register.php?action=logout\">退出</a> ');\n\t\t\t\t}";
     } else {
         echo "function getHeader() {\n\t\t\t\t\tdocument.write('<a href=\"register.php?action=reg\" class=\"user\">注册</a> <a href=\"register.php?action=login\" class=\"user\">登录</a>');\n\t\t\t\t}";
     }
 }
开发者ID:echo-tang,项目名称:XMFreamwork,代码行数:9,代码来源:Cache.class.php


示例9: __trigger

 protected function __trigger()
 {
     $accept = isset($_POST['action'][self::ROOTELEMENT]['accept']);
     $cookie = new Cookie('eu-cookie-law', YEAR, __SYM_COOKIE_PATH__, null, true);
     $cookie->set('accept', $accept);
     $result = new XMLElement(self::ROOTELEMENT);
     $result->setAttribute('result', $accept ? 'accept' : 'reject');
     return $result;
 }
开发者ID:remie,项目名称:cookie_law,代码行数:9,代码来源:event.cookielaw.php


示例10: initContent

 /**
  * Preparing hidden form with payment data before sending it to Dotpay
  */
 public function initContent()
 {
     parent::initContent();
     $this->display_column_left = false;
     $this->display_header = false;
     $this->display_footer = false;
     $cartId = 0;
     if (Tools::getValue('order_id') == false) {
         $cartId = $this->context->cart->id;
         $exAmount = $this->api->getExtrachargeAmount(true);
         if ($exAmount > 0 && !$this->isExVPinCart()) {
             $productId = $this->config->getDotpayExchVPid();
             if ($productId != 0) {
                 $product = new Product($productId, true);
                 $product->price = $exAmount;
                 $product->save();
                 $product->flushPriceCache();
                 $this->context->cart->updateQty(1, $product->id);
                 $this->context->cart->update();
                 $this->context->cart->getPackageList(true);
             }
         }
         $discAmount = $this->api->getDiscountAmount();
         if ($discAmount > 0) {
             $discount = new CartRule($this->config->getDotpayDiscountId());
             $discount->reduction_amount = $this->api->getDiscountAmount();
             $discount->reduction_currency = $this->context->cart->id_currency;
             $discount->reduction_tax = 1;
             $discount->update();
             $this->context->cart->addCartRule($discount->id);
             $this->context->cart->update();
             $this->context->cart->getPackageList(true);
         }
         $result = $this->module->validateOrder($this->context->cart->id, (int) $this->config->getDotpayNewStatusId(), $this->getDotAmount(), $this->module->displayName, NULL, array(), NULL, false, $this->customer->secure_key);
     } else {
         $this->context->cart = Cart::getCartByOrderId(Tools::getValue('order_id'));
         $this->initPersonalData();
         $cartId = $this->context->cart->id;
     }
     $this->api->onPrepareAction(Tools::getValue('dotpay_type'), array('order' => Order::getOrderByCartId($cartId), 'customer' => $this->context->customer->id));
     $sa = new DotpaySellerApi($this->config->getDotpaySellerApiUrl());
     if ($this->config->isDotpayDispInstruction() && $this->config->isApiConfigOk() && $this->api->isChannelInGroup(Tools::getValue('channel'), array(DotpayApi::cashGroup, DotpayApi::transfersGroup)) && $sa->isAccountRight($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), $this->config->getDotpayApiVersion())) {
         $this->context->cookie->dotpay_channel = Tools::getValue('channel');
         Tools::redirect($this->context->link->getModuleLink($this->module->name, 'confirm', array('order_id' => Order::getOrderByCartId($cartId))));
         die;
     }
     $this->context->smarty->assign(array('hiddenForm' => $this->api->getHiddenForm()));
     $cookie = new Cookie('lastOrder');
     $cookie->orderId = Order::getOrderByCartId($cartId);
     $cookie->write();
     $this->setTemplate("preparing.tpl");
 }
开发者ID:dotpay,项目名称:dotpay,代码行数:55,代码来源:preparing.php


示例11: __trigger

 protected function __trigger()
 {
     $xml = new XMLElement('cookie-monster');
     $cookie = new Cookie(__SYM_COOKIE_PREFIX__ . '-cookiemonster', TWO_WEEKS, __SYM_COOKIE_PATH__);
     $count = 0;
     foreach ($_GET as $key => $val) {
         if (!in_array($key, array('symphony-page', 'debug', 'profile'))) {
             $cookie->set($key, $val);
             $xml->appendChild(new XMLElement('item', $val, array('name' => $key, 'action' => strlen($val) > 0 ? 'added' : 'removed')));
             $count++;
         }
     }
     return $count == 0 ? NULL : $xml;
 }
开发者ID:pointybeard,项目名称:cookiemonster,代码行数:14,代码来源:event.cookiemonster_addgettocookie.php


示例12: __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;
 }
开发者ID:klaftertief,项目名称:language_redirect,代码行数:50,代码来源:event.language_redirect.php


示例13: doRun

function doRun()
{
    $msg = '';
    $username = mysql_real_escape_string($_POST['name']);
    $pass = mysql_real_escape_string($_POST['pass']);
    try {
        $db = new PDO('mysql:host=localhost;dbname=testData', 'root', 'root');
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $db->prepare('	SELECT 
													username, pass 
											FROM 	
													testTable
											WHERE
													username = :name
											AND 	
													pass = :pass

										');
        $stmt->bindParam(':name', $username, PDO::PARAM_STR);
        $stmt->bindParam(':pass', $pass, PDO::PARAM_STR);
        $stmt->execute();
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        if ($result == false) {
            $msg = 'sorry could not connect';
        } else {
            //$_SESSION['name'] = $username;
            /**
             * Create a cookie with the name "myCookieName" and value "testing cookie value"
             */
            $cookie = new Cookie();
            // Set cookie name
            $cookie->setName('Login');
            // Set cookie value
            $cookie->setValue("testing cookie value");
            // Set cookie expiration time
            $cookie->setTime("+1 hour");
            // Create the cookie
            $cookie->create();
            // Delete the cookie.
            //$cookie->delete();
            $msg = 'logged in as ' . $username . '<br>';
        }
    } catch (PDOException $e) {
        echo "Error:" . $e;
    }
    echo $msg;
    $db = NULL;
}
开发者ID:reshadf,项目名称:Library,代码行数:48,代码来源:index.php


示例14: showRefLink

 /**
  * [showRefLink description]
  * Route::get('{link?}', ['as' => 'reflink', 'uses' => 'LinkController@showRefLink']);
  *
  * @param [text] $link [referral link]
  *
  * @return [json] [all info abou the link]
  */
 public function showRefLink($link = null)
 {
     //  // If it has a Sponsor Cookie
     if (\Cookie::has('sponsor')) {
         return Redirect::to('/');
         // Load Referral Link View
     }
     if (is_null($link)) {
         return Redirect::to('/');
         // Redirect To HomePage
     }
     try {
         // If has $Link then Look in Database if Exist
         $link = Link::findByLink($link)->load('user.profile');
         $link = $link->toArray();
         // Note Cookie Wont Be Created if Exceeded More than 4kb
         \Cookie::queue('sponsor', $link, 2628000);
         // Return Referral View with Variable Link
         return Redirect::to('/')->with('link', $link);
         // If No Record Found Throw Exception!
     } catch (ModelNotFoundException $e) {
         // Return Back to Home
         return Redirect::to('/');
         // return view('nosponsor');
     }
 }
开发者ID:xenxa,项目名称:royalflushnetwork,代码行数:34,代码来源:LinkController.php


示例15: 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);
 }
开发者ID:aozhongxu,项目名称:web_hqoj,代码行数:35,代码来源:SetProblemController.class.php


示例16: get

 /**
  * Get cookie value(s)
  * 
  * @param string $name      Name of the cookie to get
  * @param mixed $default    [optional] Default value if cookie is not set. Default is false
  * @return mixed            Cookie stored datas
  */
 public static function get($name, $default = false)
 {
     // handling array notation
     if (preg_match('#^(.*?)\\[(.*?)\\]$#', $name, $m)) {
         if (!isset($_COOKIE[$m[1]][$m[2]])) {
             return $default;
         }
         $value = $_COOKIE[$m[1]][$m[2]];
     } else {
         if (!isset($_COOKIE[$name])) {
             return $default;
         }
         $value = $_COOKIE[$name];
     }
     // retrieve cookie content
     $cookieValue = explode('|', $value);
     // hash is not correct
     if (count($cookieValue) !== 3 || !Security::check($cookieValue[0] . $cookieValue[1], $cookieValue[2])) {
         Cookie::delete($name);
         return $default;
     }
     $value = $cookieValue[0];
     // if content is a serialized array
     if ($v = @unserialize($value)) {
         $value = $v;
     }
     return $value;
 }
开发者ID:salomalo,项目名称:php-oxygen,代码行数:35,代码来源:cookie.class.php


示例17: before

 public function before()
 {
     if ($this->request->action === 'media') {
         // Do not template media files
         $this->auto_render = FALSE;
     } else {
         // Grab the necessary routes
         $this->media = Route::get('docs/media');
         $this->api = Route::get('docs/api');
         $this->guide = Route::get('docs/guide');
         if (isset($_GET['lang'])) {
             $lang = $_GET['lang'];
             // Load the accepted language list
             $translations = array_keys(Kohana::message('userguide', 'translations'));
             if (in_array($lang, $translations)) {
                 // Set the language cookie
                 Cookie::set('userguide_language', $lang, Date::YEAR);
             }
             // Reload the page
             $this->request->redirect($this->request->uri);
         }
         // Set the translation language
         I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang);
         // Use customized Markdown parser
         define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
         // Load Markdown support
         require Kohana::find_file('vendor', 'markdown/markdown');
         // Set the base URL for links and images
         Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/';
         Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/';
     }
     parent::before();
 }
开发者ID:banks,项目名称:userguide,代码行数:33,代码来源:userguide.php


示例18: mySchool

 public function mySchool()
 {
     // $academy_id = Session::get('school_id_session');
     $academy_id = Cookie::get('school_id_session');
     $mySchool = Academy::where('id', $academy_id)->first();
     return $mySchool;
 }
开发者ID:bytrix,项目名称:witkey,代码行数:7,代码来源:BaseController.php


示例19: isLoggedIn

 /**
  * This function determines whether an there is a currently logged in
  * Author for Symphony by using the `$Cookie`'s username
  * and password. If an Author is found, they will be logged in, otherwise
  * the `$Cookie` will be destroyed.
  *
  * @see core.Cookie#expire()
  */
 public function isLoggedIn()
 {
     // Ensures that we're in the real world.. Also reduces three queries from database
     // We must return true otherwise exceptions are not shown
     if (is_null(self::$_instance)) {
         return true;
     }
     if ($this->Author) {
         return true;
     } else {
         $username = self::Database()->cleanValue($this->Cookie->get('username'));
         $password = self::Database()->cleanValue($this->Cookie->get('pass'));
         if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0) {
             $author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf("\n\t\t\t\t\t\t\t`username` = '%s'\n\t\t\t\t\t\t", $username));
             if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), true)) {
                 $this->Author = current($author);
                 self::Database()->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', sprintf(" `id` = %d", $this->Author->get('id')));
                 // Only set custom author language in the backend
                 if (class_exists('Administration')) {
                     Lang::set($this->Author->get('language'));
                 }
                 return true;
             }
         }
         $this->Cookie->expire();
         return false;
     }
 }
开发者ID:readona,项目名称:symphonyno5,代码行数:36,代码来源:class.symphony.php


示例20: ajaxAddProblemAction

 public function ajaxAddProblemAction()
 {
     $setId = Request::getPOST('set-id');
     $remote = Request::getPOST('remote');
     $problemCode = Request::getPOST('problem-code');
     // 默认题库
     Cookie::set('default_remote', $remote);
     $problemInfo = OjProblemInterface::getDetail(array('remote' => $remote, 'problem_code' => $problemCode));
     if (empty($problemInfo)) {
         $this->renderError('题目不存在!');
     }
     if ($problemInfo['hidden']) {
         $this->renderError('无法添加隐藏的题目!');
     }
     $setInfo = OjProblemSetInterface::getById(array('id' => $setId));
     if (empty($setInfo)) {
         $this->renderError('专题不存在!');
     }
     // 属主验证
     if ($this->loginUserInfo['id'] != $setInfo['user_id']) {
         $this->renderError('你没有权限操作!');
     }
     $globalIds = (array) json_decode($setInfo['problem_set'], true);
     if (in_array($problemInfo['id'], $globalIds)) {
         $this->renderError('题目已经在专题中!');
     }
     // 题目上限
     if (count($globalIds) >= ContestVars::SET_PROBLEM_LIMIT) {
         $this->renderError('题目数量达到上限,无法继续添加!');
     }
     // 更新数据
     OjProblemSetInterface::addProblem(array('id' => $setId, 'remote' => $remote, 'problem_code' => $problemCode));
     $this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功');
     $this->renderAjax(0);
 }
开发者ID:aozhongxu,项目名称:web_hqoj,代码行数:35,代码来源:ProblemController.class.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP CopixConfig类代码示例发布时间:2022-05-23
下一篇:
PHP Converter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap