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


PHP setcookie函数代码示例

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


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

示例1: logAppDevice

 public function logAppDevice($type, $token)
 {
     $forever = time() + 10 * 365 * 24 * 60 * 60;
     setcookie('device_type', $type, $forever, '/');
     setcookie('device_token', $token, $forever, '/');
     return redirect('auth/login');
 }
开发者ID:bbig979,项目名称:shoppyst,代码行数:7,代码来源:WelcomeController.php

示例2: SetCartId

 public static function SetCartId()
 {
     //Если Id корзины не задан
     if (self::$_mCartId == '') {
         // Если в сеансе есть Id корзины, получаем его оттуда
         if (isset($_SESSION['cart_id'])) {
             self::$_mCartId = $_SESSION['cart_id'];
         } elseif (isset($_COOKIE['cart_id'])) {
             self::$_mCartId = $_COOKIE['cart_id'];
             $_SESSION['cart_id'] = self::$_mCartId;
             //регенерируем cookie-файл, чтобы он
             //действовал 7 дней (604800 секунд)
             setcookie('cart_id', self::$_mCartId, time() + 604800);
         } else {
             /* Генерируем id корзины и сохраняем его в элементе класса
                $_mCartId, сеансе и cookie-файле (при последующих вызовах 
                $_mCartId будет получать значение из сеанса) */
             self::$_mCartId = md5(uniqid(rand(), TRUE));
             // Сохраняем id корзины в сеансе
             $_SESSION['cart_id'] = self::$_mCartId;
             // cookie-файл будет действовать 7 дней (604800 секунд)
             setcookie('cart_id', self::$_mCartId, time() + 604800);
         }
     }
 }
开发者ID:naOyD,项目名称:tshirtshop_g,代码行数:25,代码来源:shopping_cart.php

示例3: run

function run()
{
    $consumer = getConsumer();
    // Complete the authentication process using the server's
    // response.
    $return_to = getReturnTo();
    $response = $consumer->complete($return_to);
    // Check the response status.
    if ($response->status == Auth_OpenID_CANCEL) {
        // This means the authentication was cancelled.
        $msg = 'Verification cancelled.';
        if (isset($_COOKIE[session_name()])) {
            setcookie(session_name(), '', time() - 42000, '/');
        }
        session_destroy();
    } else {
        if ($response->status == Auth_OpenID_FAILURE) {
            // Authentication failed; display the error message.
            $msg = "OpenID authentication failed: " . $response->message;
            if (isset($_COOKIE[session_name()])) {
                setcookie(session_name(), '', time() - 42000, '/');
            }
            session_destroy();
        } else {
            if ($response->status == Auth_OpenID_SUCCESS) {
                // This means the authentication succeeded; extract the
                // identity URL and Simple Registration data (if it was
                // returned).
                $openid = $response->getDisplayIdentifier();
                $esc_identity = escape($openid);
                $_SESSION = array();
                $_SESSION['openid'] = $esc_identity;
                if ($response->endpoint->canonicalID) {
                    $escaped_canonicalID = escape($response->endpoint->canonicalID);
                    $success .= '  (XRI CanonicalID: ' . $escaped_canonicalID . ') ';
                    $_SESSION['openid'] = $escaped_canonicalID;
                }
                // AX Process
                $ax_resp = Auth_OpenID_AX_FetchResponse::fromSuccessResponse($response);
                if ($ax_resp) {
                    global $ax_data;
                    foreach ($ax_data as $ax_key => $ax_data_ns) {
                        if ($ax_resp->data[$ax_data_ns][0]) {
                            $_SESSION['ax_' . $ax_key] = $ax_resp->data[$ax_data_ns][0];
                        }
                    }
                }
            }
        }
    }
    if ($_GET["popup"] == "true") {
        include 'close.php';
    } else {
        if ($_GET["callback"] == "ax") {
            header("Location: ./ax_example.php");
        } else {
            header("Location: ./index.php");
        }
    }
}
开发者ID:ritou,项目名称:php-openid-popup-example,代码行数:60,代码来源:finish_auth.php

示例4: setCookies

 public function setCookies()
 {
     $cookieStr = "un=" . $this->userName;
     $cookieStr .= "&dn=" . $this->displayName;
     $cookieStr .= "&uid=" . $this->uid;
     $cookieExpire = 0;
     if ($this->rememberMe) {
         $cookieExpire = time() + 60 * 60 * 24 * 30;
     }
     $domainName = $_SERVER['SERVER_NAME'];
     if (!$domainName) {
         $domainName = $_SERVER['HTTP_HOST'];
     }
     if ($domainName == 'localhost') {
         $domainName = false;
     }
     setcookie("SymbiotaBase", $cookieStr, $cookieExpire, $GLOBALS["clientRoot"] ? $GLOBALS["clientRoot"] : '/', $domainName, false, true);
     //Set admin cookie
     if ($this->userRights) {
         $cookieStr = '';
         foreach ($this->userRights as $name => $vArr) {
             $vStr = implode(',', $vArr);
             $cookieStr .= $name . ($vStr ? '-' . $vStr : '') . '&';
         }
         setcookie("SymbiotaRights", trim($cookieStr, "&"), $cookieExpire, $GLOBALS["clientRoot"] ? $GLOBALS["clientRoot"] : '/', $domainName, false, true);
     }
 }
开发者ID:jphilip124,项目名称:Symbiota,代码行数:27,代码来源:ProfileManager.php

示例5: init

 public function init()
 {
     /** @var Uri $uri */
     $uri = $this->grav['uri'];
     $config = $this->grav['config'];
     $is_admin = false;
     $session_timeout = $config->get('system.session.timeout', 1800);
     $session_path = $config->get('system.session.path', '/' . ltrim($uri->rootUrl(false), '/'));
     // Activate admin if we're inside the admin path.
     if ($config->get('plugins.admin.enabled')) {
         $route = $config->get('plugins.admin.route');
         $base = '/' . trim($route, '/');
         if (substr($uri->route(), 0, strlen($base)) == $base) {
             $session_timeout = $config->get('plugins.admin.session.timeout', 1800);
             $is_admin = true;
         }
     }
     if ($config->get('system.session.enabled') || $is_admin) {
         // Define session service.
         parent::__construct($session_timeout, $session_path);
         $unique_identifier = GRAV_ROOT;
         $this->setName($config->get('system.session.name', 'grav_site') . '-' . substr(md5($unique_identifier), 0, 7) . ($is_admin ? '-admin' : ''));
         $this->start();
         setcookie(session_name(), session_id(), time() + $session_timeout, $session_path);
     }
 }
开发者ID:clee03,项目名称:metal,代码行数:26,代码来源:Session.php

示例6: run

 /**
  * 改变外观
  */
 public function run()
 {
     //求得用户的id
     $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
     //取得用户传入的参数
     $theme = $this->getParameterFromGET('id');
     if ($theme != 'default' && $theme != 'new' && $theme != 'newll') {
         $theme = 'new';
     }
     $this->db->debug = true;
     $sql = 'select count(*) as num from user_setting where user_id=?';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     if ($rows['num']) {
         $sql = 'update user_setting set user_theme=? ' . ' where user_id=?';
         $sth = $this->db->Prepare($sql);
         $this->db->Execute($sth, array($theme, $user_id));
     } else {
         $sql = 'insert into user_setting (user_theme, ' . ' user_id ) values (?, ? ) ';
         $sth = $this->db->Prepare($sql);
         $this->db->Execute($sth, array($theme, $user_id));
     }
     //更新Session设置
     $_SESSION['user']['theme'] = $theme;
     //送cookie
     if ($_COOKIE['user']) {
         $str_user_info = serialize($_SESSION['user']);
         setcookie('user', $str_user_info, time() + 60 * 60 * 24 * 365, '/', $global_config_web_domain);
     }
     setcookie('5abb_cookie_theme', $theme, time() + 60 * 60 * 24 * 365, '/', $global_config_web_domain);
     $this->forward('index.php');
 }
开发者ID:hylinux,项目名称:ltebbs,代码行数:36,代码来源:ChangeTheme.class.php

示例7: logoutAction

 public function logoutAction()
 {
     if (isset($_COOKIE['anastasia'])) {
         setcookie('anastasia', '', time() - 60 * 60 * 24 * 7, '/');
     }
     parent::logoutAction();
 }
开发者ID:sagmahajan,项目名称:aswan_release,代码行数:7,代码来源:AccountController.php

示例8: tep_session_start

  function tep_session_start() {
    global $_GET, $_POST, $HTTP_COOKIE_VARS;

    $sane_session_id = true;

    if (isset($_GET[tep_session_name()])) {
      if (preg_match('/^[a-zA-Z0-9]+$/', $_GET[tep_session_name()]) == false) {
        unset($_GET[tep_session_name()]);

        $sane_session_id = false;
      }
    } elseif (isset($_POST[tep_session_name()])) {
      if (preg_match('/^[a-zA-Z0-9]+$/', $_POST[tep_session_name()]) == false) {
        unset($_POST[tep_session_name()]);

        $sane_session_id = false;
      }
    } elseif (isset($HTTP_COOKIE_VARS[tep_session_name()])) {
      if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_COOKIE_VARS[tep_session_name()]) == false) {
        $session_data = session_get_cookie_params();

        setcookie(tep_session_name(), '', time()-42000, $session_data['path'], $session_data['domain']);

        $sane_session_id = false;
      }
    }

    if ($sane_session_id == false) {
      tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
    }

    return session_start();
  }
开发者ID:nixonch,项目名称:a2billing,代码行数:33,代码来源:sessions.php

示例9: karma_post

 function karma_post($post_id, $action = 'get')
 {
     if (!is_numeric($post_id)) {
         return;
     }
     $karma_count = get_post_meta($post_id, $this->option_key, true);
     switch ($action) {
         case 'get':
             if (!$karma_count) {
                 $karma_count = 0;
                 add_post_meta($post_id, $this->option_key, $karma_count, true);
             }
             return $karma_count;
             break;
         case 'update':
             if (isset($_COOKIE[$this->option_key . $post_id])) {
                 return $karma_count;
             }
             $karma_count++;
             update_post_meta($post_id, $this->option_key, $karma_count);
             setcookie($this->option_key . $post_id, $post_id, time() * 20, '/');
             return $karma_count;
             break;
     }
 }
开发者ID:taeche,项目名称:SoDoEx,代码行数:25,代码来源:utils.karma.php

示例10: mark

 function mark()
 {
     $markid = $this->input->getInt('markid');
     $line = "option=com_jotcache&view=main";
     $this->model->resetMark();
     $uri = Juri::getInstance();
     $domain = $uri->toString(array('host'));
     $parts = explode('.', $domain);
     $last = count($parts) - 1;
     if ($last >= 1 && is_numeric($parts[$last]) === false) {
         $domain = $parts[$last - 1] . '.' . $parts[$last];
     }
     switch ($markid) {
         case 0:
             setcookie('jotcachemark', '0', '0', '/', $domain);
             $this->setRedirect('index.php?' . $line . "&filter_mark=", JText::_('JOTCACHE_RS_MSG_RESET'));
             break;
         case 1:
             setcookie('jotcachemark', '1', '0', '/', $domain);
             $this->setRedirect('index.php?' . $line, JText::_('JOTCACHE_RS_MSG_SET'));
             break;
         case 2:
             setcookie('jotcachemark', '2', '0', '/', $domain);
             $this->setRedirect('index.php?' . $line, JText::_('JOTCACHE_RS_MSG_RENEW'));
             break;
         default:
             break;
     }
 }
开发者ID:naka211,项目名称:myloyal,代码行数:29,代码来源:controller.php

示例11: mw_logout

function mw_logout()
{
    $cookiesSet = array_keys($_COOKIE);
    for ($x = 0; $x < count($cookiesSet); $x++) {
        setcookie($cookiesSet[$x], "", time() - 1);
    }
}
开发者ID:eellak,项目名称:gpchild-ellak,代码行数:7,代码来源:functions.php

示例12: login

 /**
  * 后台登陆控制器
  */
 public function login()
 {
     $arr = array('user_login' => I('user_login'), 'user_pass' => encrypt(I('user_pass'), C('ENCRYPTION_KEY')), 'remember-me' => I('remember-me'));
     //处理下次自动登录
     if ($arr['remember-me'] == 1) {
         $account = $arr['user_login'];
         $ip = get_client_ip(0, true);
         $value = $account . '|' . $ip;
         $value = encrypt($value, C('ENCRYPTION_KEY'));
         @setcookie('remember-me', $value, time() + 7 * 24 * 3600, "/");
     }
     $user = M('user')->where(array('user_login' => $arr['user_login']))->find();
     $userinfo = D('user')->getInfo($user['id']);
     if ($user['user_status'] == 0) {
         $this->error('账号被禁用,请联系管理员...');
     }
     if ($user['user_type'] != '管理员') {
         $this->error('无权限登录...');
     }
     if (!$user || $user['user_pass'] != $arr['user_pass']) {
         $this->error('账号密码错误,请重试...');
     }
     $data = array('id' => $user['id'], 'last_login_ip' => get_client_ip(0, true), 'last_login_time' => date("Y-m-d H:i:s"));
     $result = M('user')->save($data);
     if (!$result) {
         $this->error('登录失败,请重试...');
     }
     session('uid', $user['id']);
     session('username', $userinfo['username']);
     session('last_login_time', $data['last_login_time']);
     session('last_login_ip', $data['last_login_ip']);
     $this->success('登陆成功', U('Index/index'));
 }
开发者ID:lizhi0610,项目名称:hgnu,代码行数:36,代码来源:LoginController.class.php

示例13: setCookieValue

 /**
  * Set Cookie Value
  *
  * @param string $key
  * @param $value
  * @return void
  */
 public function setCookieValue($key, $value, $exp = NULL)
 {
     if ($key) {
         $exp = $exp ? $exp : mktime(0, 0, 0, 12, 32, 2080);
         setcookie('Tx_Nboevents_Reservation_' . $key, serialize($value), $exp, "/");
     }
 }
开发者ID:noelboss,项目名称:nboevents,代码行数:14,代码来源:Cookies.php

示例14: _unsetcookies

/**
 * 
 */
function _unsetcookies()
{
    setcookie('username', '', time() - 1);
    setcookie('uniqid', '', time() - 1);
    _session_destroy();
    _location(null, 'index.php');
}
开发者ID:PantaSun,项目名称:Multi-user-system-messages,代码行数:10,代码来源:globe.func.php

示例15: pmRestLogin

function pmRestLogin($clientId, $clientSecret, $username, $password)
{
    global $pmServer, $pmWorkspace;
    $postParams = array('grant_type' => 'password', 'scope' => '*', 'client_id' => $clientId, 'client_secret' => $clientSecret, 'username' => $username, 'password' => $password);
    $ch = curl_init("{$pmServer}/{$pmWorkspace}/oauth2/token");
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $oToken = json_decode(curl_exec($ch));
    $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($httpStatus != 200) {
        print "Error in HTTP status code: {$httpStatus}\n";
        return null;
    } elseif (isset($oToken->error)) {
        print "Error logging into {$pmServer}:\n" . "Error:       {$oToken->error}\n" . "Description: {$oToken->error_description}\n";
    } else {
        //At this point $oToken->access_token can be used to call REST endpoints.
        //If planning to use the access_token later, either save the access_token
        //and refresh_token as cookies or save them to a file in a secure location.
        //If saving them as cookies:
        setcookie("access_token", $oToken->access_token, time() + 3600);
        setcookie("refresh_token", $oToken->refresh_token);
        //refresh token doesn't expire
        setcookie("client_id", $clientId);
        setcookie("client_secret", $clientSecret);
        //If saving to a file:
        //file_put_contents("oauthAccess.json", json_encode($oToken));
    }
    return $oToken;
}
开发者ID:kshpikat,项目名称:ember-challenge,代码行数:32,代码来源:_index.php


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