First, write the following simple code :
<?php
setcookie('a','value');
print $_COOKIE['a'];
On first visit , Report errors :
The reason for the error is $_COOKIE['a'] Does not exist .
 
Second visit :
 
ask : Why the first time I visited , Will it cookie Well ?? I'm not setting up first , Get it again ??
answer : Use firefox Of firebug see ” The Internet “:
 
client :
You can see , browser ( client ) Make a request to the server , When you make a request , Various parameters are included in the request header information , Tell the server , What kind of text do I want to receive (Accept)、 What encoding format (Accept-Encoding)、 What language (Accept-Language) wait , Of course , Also put Cookie It's also sent to the server (Cookie).
 
Server side :
First step :setcookie('a','value')
because cookie It's set on the client side ,setcookie The function itself cannot set cookie, It can only tell the browser in the form of header information that : brother , I'm going to set up a cookie, The key is a, The value is value, You set it up for me at your place . You can also understand it as :” Come on , I'm happy today , I'll give you a cookie “.
 
The second step :$_COOKIE['a']
$_COOKIE['a'] It's simple , The operation is brought in the browser cookie In a string The search key is a Of cookie, And return its value .
 
 
Obviously , This ” The key is a“ Of cookie It's impossible to find , Because when the client accesses the server , This cookie It doesn't exist at all , And the first step is to set up cookie The header information , It has not been returned to the client (php The statement will not be returned to the client until it is executed from top to bottom )
 
The third step : Server returns information
among , The returned header contains ”Set-Cookie a=value“, The browser receives this header message , hold cookie Put it in a file on the computer , For different browsers cookie It seems that the location of the storage is different , This is beyond the scope of this article .
 
Refresh the browser , When you visit the server again , Again , It also brings a lot of header information to the server , Only this time cookie in , Just one more a=value 了 . My heart $_COOKIE['a'] Naturally, we can start from cookie The key found in the string is a Of cookie Value .
 

Why refresh to get cookie More articles about

  1. Cookie Use 、Cookie Detailed explanation 、HTTP cookies Detailed explanation 、 obtain cookie Methods 、 Client acquisition Cookie、 In depth analysis of cookie

    Cookie It refers to some websites in order to identify users . Conduct session Data that is tracked and stored on the user's local terminal ( Usually encrypted ), For example, some websites need to log in to access a certain page , Before you log in , You are not allowed to grab the content of a certain page . Then I ...

  2. js obtain cookie Values stored in

    Recently, I read the test paper and found that I would be very scarce , The first question puzzled me , Know there's this thing , But it's not actually done . ========================================= cookie ...

  3. Simulate user login ( obtain cookie/ Instantiation session)

    The first method : Saved through a local browser cookie Log in url1 = 'https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2F ...

  4. Cross domain results in failure to obtain cookie

    The first frame I use is vue, The request agreement uses ajax, The cross domain approach is to use reverse proxy , In my previous blog post, I explained in detail , If you are interested, you can check it , In the process of identity authentication permission restriction , There are people backstage http-header Of respon ...

  5. XSS obtain cookie And make use of

    obtain cookie Using code cookie.asp <html> <title>xx</title> <body> <%testfile = Serve ...

  6. 【 Interface automation 】selenium Libraries are also useful ( obtain cookie)

    I believe some children's shoes are making interfaces . In other words, in the process of interface automation testing, we will encounter such a scenario : Test interface , Only after logging in can the request be successful . So how to solve it ? In the spirit of teamwork , Let's go and let the development students open a back door , Here you are " ...

  7. js obtain cookie

    js obtain cookie I used to use jQuery.cookie To get cookie, Simple though , But there is one more plug-in in the project , I don't think it's very good , Here's my package js Native acquisition cookie Function of . function get ...

  8. javascript Set and get cookie The general method of

    // obtain cookie  function getCookieValue(cookieName)  {     var cookieValue = document.cookie;     var co ...

  9. adopt js obtain cookie Examples and simple analysis of

    Today I met a man in firefox Next swfupload Upload time session Inconsistency When a project encounters multiple file uploads ,firefox Next , Server side session Get inconsistent issues . terms of settlement : terms of settlement : take ses ...

Random recommendation

  1. Shi Hang 416 Homework 10 &amp; summary

    Homework 1:  Calculate the sum and difference of two numbers . Request to customize a function #include <stdio.h> void sum_diff(float op1,float op2,float *psum , flo ...

  2. [BTS] The value &quot;&quot; for the property InboundId is invalid

    Microsoft.ServiceModel.Channels.Common.MetadataException: Retrieval of Operation Metadata has failed ...

  3. Qt Message mechanisms and events ( Two )

    3、 ... and , Event filter occasionally , Objects need to be viewed . Even to intercept events sent to another object . for example , The dialog may want to block key events , Don't let other components receive : Or to change the default handling of the Enter key . Through the previous chapters , We already know ,Qt Created QE ...

  4. C# Object oriented fundamentals :virtual Method ,abstract Method , difference

    virtual Keywords are used to decorate methods . attribute . Indexer or event declaration , And so that they can be overridden in derived classes . By default , Methods in classes are non virtual , Non virtual methods cannot be covered in subclasses (override), But it can be hidden (new), But this ...

  5. java8 in Lambda Expression and Stream API

    One .Lambda expression 1. Grammar format Lambda It's an anonymous function , You can pass code . Use “->” The operator , Changing the operator will lambda In two parts : left : It specifies Lambda All the parameters required by the expression On the right side : It specifies ...

  6. php Array and object conversion functions

    /**  * Array turn object  *  * @param array $arr Array  * @return object  */ function array_to_object($arr) {     ...

  7. Game client Session Unified management of

    Read this system article need some C Language . Basic knowledge of data structure and network ! explain : Because there will be thousands of clients on the game server side making connection requests , So we need to do some simple session management ! Here's the picture 1. Briefly explain Unified distribution and management , We need to ...

  8. [luogu4201][bzoj1063] Design the route 【 Tree form DP】

    Title Description Z China is located in the remote and magical Oriental peninsula , In small Z During the reign of the people's Republic of China, roads became the main means of transportation here .Z The KMT has n city , Some cities are connected by two-way highways . It's amazing that Z Every city in China is in a different longitude , And at most with one ...

  9. redgate Of mysql Architecture comparison and data comparison tools

    redgate Of mysql Architecture comparison and data comparison tools Recently, online data needs to be compared in terms of architecture , Compare... On two servers mysql The architecture of the database on the instance Data comparison can be used percona Of pt-table-checksum and pt- ...

  10. grep and curl -d Wait for the order In single quotation marks, regular , And using variable methods

    a='{"type":"d_log", "log_format":"d_log", "exclude" ...