Home > Backend Development > PHP Tutorial > Detailed introduction to cookie usage in php_PHP tutorial

Detailed introduction to cookie usage in php_PHP tutorial

WBOY
Release: 2016-07-13 17:14:50
Original
814 people have browsed it

A cookie is a small file sent to the browser, which can be used to record user operations, such as which files were accessed, etc.

Write cookie

}
The code is as follows
 代码如下 复制代码

setcookie(name, value, expire, path, domain);

function w_cookie($n, $c, $e = 0,$isdes=1)
 {
   if($isdes==1){$c=endes($c,deskey);}
      $exp = time() + 3600 * 24 * 30;
      if($e == 0)
     {
          setcookie($n, $c, $exp,"/");
     }
     else
     {
      setcookie($n, $c,0,"/");
      }
 }

Copy code


setcookie(name, value, expire, path, domain);


function w_cookie($n, $c, $e = 0,$isdes=1)

{

if($isdes==1){$c=endes($c,deskey);}

$exp = time() + 3600 * 24 * 30;
 代码如下 复制代码

function cookie($var, $value='', $time=0, $path='', $domain=''){
$_COOKIE[$var] = $value;
  if(is_array($value)){
      foreach($value as $k=>$v){
        setcookie($var.'['.$k.']', $v, $time, $path, $domain, $s);
      }
  }else{
        setcookie($var, $value, $time, $path, $domain, $s);
  }
}
 
//调用方法
 
cookie("website","安卓主题","./","www.hzhuti.com");
//

If($e == 0)

{

​​​​​ setcookie($n, $c, $exp,"/");

}

      else
 代码如下 复制代码

$time = time() + 300;    //5分钟过期
$code = md5($string . $time . $salt);
setcookie('check_time', $time);
setcookie('code', $code);

//验证部分
$TIME = time();
if($check_time < $TIME)//如果服务器时间比验证时间大,算过期
//expire过期

if(md5($string . $check_time . $salt) !== $code)

{

setcookie($n, $c,0,"/");

}

Example 1 Write cookie
The code is as follows Copy code
function cookie($var, $value='', $time=0, $path='', $domain=''){ $_COOKIE[$var] = $value; if(is_array($value)){

foreach($value as $k=>$v){           setcookie($var.'['.$k.']', $v, $time, $path, $domain, $s);

}
}else{           setcookie($var, $value, $time, $path, $domain, $s); } } //Call method cookie("website","Android theme","./","www.hzhuti.com"); // Example 2 Prevent duplicate submissions
The code is as follows Copy code
$time = time() + 300; //Expires in 5 minutes $code = md5($string . $time . $salt); setcookie('check_time', $time); setcookie('code', $code); //Verification part $TIME = time(); if($check_time < $TIME)//If the server time is greater than the verification time, it is considered expired //expire expires   if(md5($string . $check_time . $salt) !== $code) For more information about php cookie usage, please refer to: http://www.bKjia.c0m/tags.php/php%20cookie/ http://www.bkjia.com/PHPjc/628924.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628924.htmlTechArticleCookie is a small file sent on the browser side, which can be used to record user operations, such as visits Those files, etc. are written into cookies. The code is as follows. Copy the code setcookie(name, va...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template