本文整理汇总了PHP中setCookie函数的典型用法代码示例。如果您正苦于以下问题:PHP setCookie函数的具体用法?PHP setCookie怎么用?PHP setCookie使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setCookie函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* โหลด GCMS เพื่อแสดงผลหน้าเว็บไซต์
*/
public function run()
{
/**
* inint session
*/
session_start();
if (!ob_get_status()) {
if (extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
// เปิดใช้งานการบีบอัดหน้าเว็บไซต์
ob_start('ob_gzhandler');
} else {
ob_start();
}
}
/**
* โหลด GCMS
*/
$this->inint();
/**
* save variable
*/
setCookie('gcms_language', LANGUAGE, time() + 3600 * 24 * 365);
/**
* create Router
*/
self::createClass('Core\\Router');
/**
* return current instance
*/
return self::$instance;
}
示例2: send
protected function send()
{
if (!headers_sent()) {
$code = $this->getStatusCode();
$version = $this->getProtocolVersion();
if ($code !== 200 || $version !== '1.1') {
header(sprintf('HTTP/%s %d %s', $version, $code, $this->getReasonPhrase()));
}
foreach ($this->headers as $key => $value) {
$key = ucwords(strtolower($key), '-');
if (is_array($value)) {
$value = implode(',', $value);
}
header(sprintf('%s: %s', $key, $value));
}
foreach ($this->cookies as $cookie) {
list($name, $value, $expire, $path, $domain, $secure, $httponly) = $cookie;
setCookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}
}
$body = $this->getBody();
if ($body instanceof IteratorStream) {
foreach ($body->iterator() as $string) {
echo $string;
}
} else {
echo (string) $body;
}
}
示例3: reset
public function reset()
{
global $clientRoot;
setCookie("colltaxa", "", time() - 3600, $clientRoot ? $clientRoot : '/');
setCookie("collsearch", "", time() - 3600, $clientRoot ? $clientRoot : '/');
setCookie("collvars", "", time() - 3600, $clientRoot ? $clientRoot : '/');
$this->reset = 1;
if (array_key_exists("db", $this->searchTermsArr) || array_key_exists("oic", $this->searchTermsArr)) {
//reset all other search terms except maintain the db terms
$dbsTemp = "";
if (array_key_exists("db", $this->searchTermsArr)) {
$dbsTemp = $this->searchTermsArr["db"];
}
$clidTemp = "";
if (array_key_exists("clid", $this->searchTermsArr)) {
$clidTemp = $this->searchTermsArr["clid"];
}
unset($this->searchTermsArr);
if ($dbsTemp) {
$this->searchTermsArr["db"] = $dbsTemp;
}
if ($clidTemp) {
$this->searchTermsArr["clid"] = $clidTemp;
}
}
}
示例4: logUserOut
function logUserOut()
{
setSessionVar('login', false);
setCookie('keep_log', '0', time() - 3600, '/', $_SERVER['HTTP_HOST'], false, true);
unset($_COOKIE['keep_log']);
quitSession();
}
示例5: catchEvent
public function catchEvent($moduleGroup, $moduleName, $event, $parameters)
{
global $session;
global $parametersMod;
if (!isset($session) || $session->loggedIn()) {
//in admin.php $session is not defined on time of this event.
return;
}
if (!$parametersMod->getValue('community', 'user', 'options', 'enable_autologin')) {
return;
}
if ($moduleGroup == 'administrator' && $moduleName == 'system' && $event == 'init') {
if (isset($_COOKIE[Config::$autologinCookieName])) {
$jsonData = $_COOKIE[Config::$autologinCookieName];
$data = json_decode($jsonData);
if ($data && isset($data->id) && isset($data->pass)) {
$tmpUser = Db::userById($data->id);
if ($tmpUser) {
if (md5($tmpUser['password'] . $tmpUser['created_on']) == $data->pass) {
$session->login($tmpUser['id']);
setCookie(Config::$autologinCookieName, json_encode(array('id' => $tmpUser['id'], 'pass' => md5($tmpUser['password'] . $tmpUser['created_on']))), time() + $parametersMod->getValue('community', 'user', 'options', 'autologin_time') * 60 * 60 * 24, Config::$autologinCookiePath, Config::getCookieDomain());
}
}
}
}
}
}
示例6: sendHeader
public function sendHeader()
{
// session必须要先于header处理
// 否则会覆盖header内对于Cache-Control的处理
if ($this->session) {
if (!isset($_SESSION)) {
session_start();
}
foreach ($this->session as $sess) {
list($path, $val) = $sess;
array_set($_SESSION, $path, $val);
}
$this->session = array();
}
foreach ($this->cookie as $name => $config) {
list($value, $expire, $path, $domain, $secure, $httponly) = $config;
setCookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}
$this->cookie = array();
if (is_integer($this->code) && $this->code != 200) {
if ($status = self::httpStatus($this->code)) {
header($status);
}
}
foreach ($this->header as $name => $value) {
$header = $value === null ? $name : $name . ': ' . $value;
header($header);
}
$this->header = array();
return $this;
}
示例7: cookie
static function cookie()
{
$param = func_get_args();
if (func_num_args() === 1) {
$key = $param[0];
if (is_array($param[0])) {
$key = $param[0][0];
if (isset($param[0][1]) && $param[0][1]) {
$key = secure::token($param[0][0]);
}
}
if (isset($_COOKIE[$key])) {
if (is_numeric($_COOKIE[$key]) && $_COOKIE[$key] <= 2147483647) {
return $_COOKIE[$key] + 0;
}
return secure::symbol(trim(htmlspecialchars(strip_tags($_COOKIE[$key]))));
}
return null;
}
list($key, $value) = $param;
$expire = isset($param[2]) ? $param[2] : 31536000;
if (isset($param[3]) && $param[3]) {
$key = secure::token($key);
}
$expire += time();
return setCookie($key, $value, $expire, '/', trim(SITE_DOMAIN, 'www.'));
}
示例8: verify
function verify($name, $password, $remember)
{
$t = new twitter($name, $password, user_type());
$user = $t->veverify();
if (!isset($user->error) && isset($user->name)) {
$time = $remember ? time() + 3600 * 24 * 365 : 0;
setEncryptCookie('twitterID', $name, $time, '/');
setEncryptCookie('twitterPW', $password, $time, '/');
setcookie('friends_count', $user->friends_count, $time, '/');
setcookie('statuses_count', $user->statuses_count, $time, '/');
setcookie('followers_count', $user->followers_count, $time, '/');
setcookie('imgurl', $user->profile_image_url, $time, '/');
setcookie('name', $user->name, $time, '/');
$twDM = $t->directMessages(false, false, 1);
if ($twDM === false) {
} else {
if (count($twDM) == 0) {
} else {
setCookie("meSinceId", $twDM[0]->id);
}
}
return true;
} else {
return false;
}
}
示例9: clear
public static function clear()
{
$session = Factory::make('session');
$user_login_key_old = $session->get("_login_cookie_key");
setCookie($user_login_key_old, '', time() - 1, '/');
$session->clear();
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!Session::has('role')) {
return redirect('/login');
}
if (!isset($_COOKIE['login'])) {
$visitorCount = 1;
}
$setTime = time() + 3600;
if (isset($_COOKIE['login'])) {
$visitorCount = $_COOKIE['login'] + 1;
setCookie('login', $visitorCount, $setTime);
} else {
setCookie('login', $visitorCount, $setTime);
}
if (!Session::has('anchor')) {
session(['anchor' => '2']);
}
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
$old_error_handler = set_error_handler("myErrorHandler");
return $next($request);
}
示例11: erase
/**
* @return void
* @param string $name
*/
public function erase($name)
{
if (!headers_sent()) {
setCookie($name, null, -1, '/', $this->domain, $this->secure, $this->httpOnly);
}
unset($_COOKIE[$name]);
}
示例12: generateCookie
public static function generateCookie($jabberId, $secret)
{
$id = trim($jabberId . ":" . $secret);
$cookie = setCookie("tokboxId", $id, 0);
$url = Site_Config::BASE_SITE . "index.php";
header("Location: {$url}");
}
示例13: setAuthCookie
private function setAuthCookie($md5_pw)
{
$remember_time = time() + 60 * 60 * 24 * 30;
$user = $this->getSessionUser();
$auth_token = $this->createAuthToken($user->userid, $user->email, $md5_pw);
setCookie("sc_auth", $auth_token, $remember_time);
}
示例14: index_action
function index_action()
{
if ($_COOKIE['uid'] != "" && $_COOKIE['username'] != "") {
if ($_GET['type'] == "out") {
if ($this->config['sy_uc_type'] == "uc_center") {
$M = $this->MODEL();
$M->uc_open();
$logout = uc_user_synlogout();
} elseif ($this->config['sy_pw_type']) {
include APP_PATH . "/api/pw_api/pw_client_class_phpapp.php";
$username = $_SESSION['username'];
$pw = new PwClientAPI($username, "", "");
$logout = $pw->logout();
$this->unset_cookie();
} else {
$this->unset_cookie();
}
} else {
$this->ACT_msg("index.php", "您已经登录了!");
}
}
if ($_GET['backurl'] == '1') {
setCookie("backurl", $_SERVER['HTTP_REFERER'], time() + 60);
}
if (!$_GET['usertype']) {
$_GET['usertype'] = 1;
}
$this->yunset("usertype", $_GET['usertype']);
$this->yunset("loginname", $_COOKIE['loginname']);
$this->seo("login");
$this->yun_tpl(array('index'));
}
示例15: setCookie
/**
* 设置身份验证Cookie(sid)
*/
public function setCookie()
{
if (!self::$data[$this->uid]['islogin']) {
throw new userexception('用户未登陆,不能设置身份验证Cookie。', 2503);
}
return setCookie(COOKIE_A . 'sid', self::$data[$this->uid]['sid'], $_SERVER['REQUEST_TIME'] + DEFAULT_LOGIN_TIMEOUT, COOKIE_PATH, COOKIE_DOMAIN);
}