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