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

PHP setcookie函数代码示例

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

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



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


示例16: like_post

 function like_post($post_id, $action = 'get')
 {
     if (!is_numeric($post_id)) {
         return;
     }
     switch ($action) {
         case 'get':
             $like_count = get_post_meta($post_id, '_qode-like', true);
             if (!$like_count) {
                 $like_count = 0;
                 add_post_meta($post_id, '_qode-like', $like_count, true);
             }
             return '<span class="qode-like-count">' . $like_count . '</span>';
             break;
         case 'update':
             $like_count = get_post_meta($post_id, '_qode-like', true);
             if (isset($_COOKIE['qode-like_' . $post_id])) {
                 return $like_count;
             }
             $like_count++;
             update_post_meta($post_id, '_qode-like', $like_count);
             setcookie('qode-like_' . $post_id, $post_id, time() * 20, '/');
             return '<span class="qode-like-count">' . $like_count . '</span>';
             break;
     }
 }
开发者ID:sdxlgc,项目名称:net-wp_sdgcxl-htdocs,代码行数:26,代码来源:qode-like.php


示例17: logout

 function logout()
 {
     //echo "here";
     setcookie("logged_in", "", time() - 3600);
     header('Location: ' . $_SERVER['PHP_SELF']);
     exit;
 }
开发者ID:promoso,项目名称:HVAC,代码行数:7,代码来源:installer.php


示例18: end

 public static function end()
 {
     if (self::$checksum == md5(serialize(self::$d))) {
         return;
     }
     if (empty(self::$d)) {
         // session is empty; we can abandon it
         setcookie(self::COOKIE_NAME, '', time() - 3600, '/');
         return;
     }
     if (!self::$sessionModel && !self::$driver) {
         if (isset($GLOBALS['_CONFIG']['cache_driver'])) {
             self::$driver = \jmvc::cache();
         } else {
             self::$sessionModel = new \jmvc\models\Session();
         }
     }
     $key = self::id() ?: self::generate_id();
     if (self::$driver) {
         self::$driver->set($key, self::$d, ONE_DAY);
     } else {
         if (self::$sessionModel) {
             self::$sessionModel->id = $key;
             self::$sessionModel->data = serialize(self::$d);
             self::$sessionModel->save();
         }
     }
 }
开发者ID:jonthornton,项目名称:JMVC,代码行数:28,代码来源:session.php


示例19: signOut

 public static function signOut()
 {
     // clear the cookies
     setcookie('user_id', '', time() - 3600, COOKIE_PATH, COOKIE_DOMAIN);
     setcookie('username', '', time() - 3600, COOKIE_PATH, COOKIE_DOMAIN);
     setcookie('admin', '', time() - 3600, COOKIE_PATH, COOKIE_DOMAIN);
 }
开发者ID:malimu,项目名称:Pipeline,代码行数:7,代码来源:session.class.php


示例20: login

function login($user, $pass)
{
    $con = new db();
    $conc = $con->c();
    $kcook = intval($_POST["remember"]);
    $q = mysqli_query($conc, "SELECT `id`,`user`,`name`,`email`,`img1`,`img2`,`img3`,`bgcolor` FROM `users` WHERE (`user` = '{$user}' OR `email` ='{$user}') AND pass = '{$pass}'");
    if (mysqli_num_rows($q) == 1) {
        $r = mysqli_fetch_array($q);
        setcookie("u", $r[1], time() + 52 * 60 * 60 * 24 * 7);
        $_SESSION["uid"] = $r[0];
        $_SESSION["user"] = $r[1];
        $_SESSION["name"] = $r[2];
        $_SESSION["email"] = $r[3];
        $_SESSION["p"] = $pass;
        $_SESSION["color"] = $r[7];
        $_SESSION["img1"] = $r[4];
        $_SESSION["img2"] = $r[5];
        $_SESSION["img3"] = $r[6];
        $_SESSION["ula"] = md5("{$r['1']} {$pass} {$r['0']}");
        $con->close_db_con($conc);
        if ($kcook == 1) {
            setcookie("u", $r[1], time() + 2 * 60 * 60 * 24 * 7);
            setcookie("p", $pass, time() + 2 * 60 * 60 * 24 * 7);
        }
        return true;
    } else {
        return false;
    }
}
开发者ID:gottsohn,项目名称:muzikkitchen,代码行数:29,代码来源:index.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP setdefault函数代码示例发布时间:2022-05-15
下一篇:
PHP setcache函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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