Php simple cookie problems ~

Source: Internet
Author: User
Php simple cookie problems ~~ Make a simple website login interface and logout interface, and set the cookie in the php code on the login interface. if you want to display it in this program, it cannot be displayed, the code on the logout page is displayed. The code for setting and displaying cookies in the login code is as follows // you can set the cookie information of the local machine $ set_info & nbsp php for simple Cookie problems ~~
Make a simple website login interface and logout interface, and set the cookie in the php code on the login interface. if you want to display it in this program, it cannot be displayed, the code on the logout page is displayed.
The code for setting and displaying cookies in the logon code is as follows:

// Set local Cookie information
$ Set_info = $ record [1]. "|". $ record [3]; // record is the query result from the database. this is correct.
Setcookie ("userinfo", $ set_info, time () + 60*60*24); // set the local cookie
// Extract information from cookies
$ Pp = explode ("|", $ _ COOKIE [userinfo]); // Extract two pieces of information from the cookie.
Echo $ pp [0]. "----". $ pp [1]."
"; // Output this information. This is where the problem occurs! The printed items are empty and nothing exists. the userinfo of the last line is added with single quotation marks without double quotation marks.


But it can be displayed in the code of the logout interface.

// Read the information in the Cookie
Echo "the following is the content of the Cookie variable:
";
$ Pp = explode ("|", $ _ COOKIE ["userinfo"]);
Echo $ pp [0]. "----". $ pp [1]."
"; // It can be displayed normally !!!!
// Release the Cookie variable
Setcookie ("userinfo ","");


Why !!! Is there any other mechanism for cookie? Why is it not displayed during login? Please answer! Php? Cookie
------ Solution --------------------
The cookie is visible only when the next page is loaded
------ Solution --------------------
 


Reference:
Okay, I suddenly understood it ~~~~ It turns out that you can understand the problem after posting .... This is an idiot ~ Let's see you here ~~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.