PHP Learning Cookies

Source: Internet
Author: User
Tags setcookie
Cookies are a very frequent use of knowledge in development, telling you about the common sense and use of cookies in PHP learning.
What is a cookie?
As defined in the official documentation, a cookie is a way for a server or script to maintain information on a client workstation under the HTTP protocol. A cookie is a small text file that is saved by a Web service on a user's browser and contains information about the user being accessed. It is a different solution to the session, but also solves the problem of maintaining a state between multiple things, while maintaining a neat URL, which can be saved as a script on the client machine, by sending an HTTP header that contains specific data and has the following format. Set a cookie on the user machine:
Set-cookie:cookie_name=myfirstcookie; [Expires=date;] [Path=path]
[Domain=damain_name;] [Secure]
The above code will create a cookie named Cookie name with a value of Myfirstcookie. The parameters in square brackets [] are optional, the parameter expires domain sets the cookie expiration date, if not set, and is not manually deleted, the cookie will always be valid; path and domain together specify URL or cookie-related URLs The session keyword means that no cookie is sent in the normal HTTP sequence.
How do I use cookies in PHP?
To use cookies in PHP, you must first set up a cookie. I can set cookies manually with Setcookie ().
such as: Setcookie (string name [, string value [, int expire [, String path [, string domain [, int secure]]]);
In addition to name, the others are optional.
A simple example of setting a cookie:
Setcookie (' NAME ', ' Messi ');
Setcookie (' NAME ', ' Messi ', Time () +3600, '/web ');

The above is the content of PHP learning cookies, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.