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

Detailed introduction to cookie usage in php_PHP tutorial

Jul 13, 2016 pm 05:14 PM
cookie php introduce send Can exist document yes Browser usage end Record detailed

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Apr 28, 2025 pm 07:51 PM

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Ouyi official website entrance Ouyi official latest entrance 2025 Ouyi official website entrance Ouyi official latest entrance 2025 Apr 28, 2025 pm 07:48 PM

Choose a reliable trading platform such as OKEx to ensure access to the official entrance.

Composer: Aiding PHP Development Through AI Composer: Aiding PHP Development Through AI Apr 29, 2025 am 12:27 AM

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Binance official website entrance Binance official latest entrance 2025 Binance official website entrance Binance official latest entrance 2025 Apr 28, 2025 pm 07:54 PM

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.

What is the significance of the session_start() function? What is the significance of the session_start() function? May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

How to configure the character set and collation rules of MySQL How to configure the character set and collation rules of MySQL Apr 29, 2025 pm 04:06 PM

Methods for configuring character sets and collations in MySQL include: 1. Setting the character sets and collations at the server level: SETNAMES'utf8'; SETCHARACTERSETutf8; SETCOLLATION_CONNECTION='utf8_general_ci'; 2. Create a database that uses specific character sets and collations: CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci; 3. Specify character sets and collations when creating a table: CREATETABLEexample_table(idINT

Laravel Live Chat Application: WebSocket and Pusher Laravel Live Chat Application: WebSocket and Pusher Apr 30, 2025 pm 02:33 PM

Building a live chat application in Laravel requires using WebSocket and Pusher. The specific steps include: 1) Configure Pusher information in the .env file; 2) Set the broadcasting driver in the broadcasting.php file to Pusher; 3) Subscribe to the Pusher channel and listen to events using LaravelEcho; 4) Send messages through Pusher API; 5) Implement private channel and user authentication; 6) Perform performance optimization and debugging.

See all articles