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


PHP Cookie类代码示例

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


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


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