PHP Create, get cookie and basic Essentials analysis, phpcookie_php tutorial

Source: Internet
Author: User

PHP Create, get cookie and basic essentials analysis, Phpcookie


This paper analyzes the PHP creation, the acquisition of cookies and the basic points. Share to everyone for your reference. Specific as follows:

Assume: cookie1.php file
Copy the Code code as follows: <?php
Setcookie ("name", "Baidu", Time () +60);
echo "Save Cookie";
?>
Required parameters are three:

(1) The first parameter: name is the key value, set itself;
(2) The second parameter: "Baidu" in the example indicates the value of the key value name;
(3) The third parameter: Indicates an expiration time of +60, indicating an expiration time of 60 seconds;

Examples of cookie code parsing, and basic points

1, when the browser opens cookie1.php, the server will be information: SET-COOKIE:NAME=%B0%D9%B6%C8; Expires=tue, 06-nov-2012 16:09:27 GMT (Note: This information can be viewed with the Grab kit tool) to respond to HTTP requests, the client browser obtains this information and saves it in a cookie file (different browsers and operating systems, Save location is not the same as file type)
2, if the third time parameter is not set, the default is the end of the session (close the browser), the cookie expires (in this case, the cookie is saved in the browser cache).
3, the cookie can only save string information, that is, the object cannot be saved (session can save the object).
4, if the key value is Chinese, the default use UrlEncode way, the Chinese transcoding.
5. When the cookie is saved, it is saved in clear text, so it needs to be processed when the password is saved, such as MD5.
6. You can save multiple cookies.
7, the same page of different cookies, save the time can be set to not the same.
8. A website should have a file that holds cookies (if a cookie is set).

Get cookies

Files: cookie2.php
Copy the Code code as follows: <?php
echo "

";
Print_r ($_cookie);
echo $_cookie[' name '];
?>
$_cookie is a predefined variable (an array) that can be used to output a cookie in the cookie's effective time.
Description of the knowledge: when the browser accesses the cookie2.php page, the cookie information is transmitted to the server, which is specified by the HTTP protocol (can be viewed using the Grab kit tool, for example)

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/947919.html www.bkjia.com true http://www.bkjia.com/PHPjc/947919.html techarticle PHP Create, get cookie and basic essentials analysis, Phpcookie This article analyzes the PHP creation, access to cookies and basic points. Share to everyone for your reference. As follows: Suppose ...

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