PHP features-session mechanism 1-Cookie usage

Source: Internet
Author: User
PHP supports HTTPcookie transparently. Cookie is a mechanism for storing data in a remote browser and tracking and identifying users. You can use the setcookie () or setrawcookie () function to set the cookie. PHP supports HTTP cookies transparently. Cookie is a mechanism for storing data in a remote browser and tracking and identifying users. You can use the setcookie () or setrawcookie () function to set the cookie. Cookie is a part of the HTTP header. Therefore, the setcookie () function must be called before other information is output to the browser. This is similar to the limitation on the header () function. You can use the output buffer function to delay the script output until all cookies or other HTTP headers are set as needed.
Example #1 setcookie () Example

 

If variables_order contains "C", any cookie sent from the client will be automatically included in the $ _ COOKIE automatic global array. If you want to set multiple values for a cookie variable, you must add the [] symbol after the cookie name.

  $value) {          $name = htmlspecialchars($name);          $value = htmlspecialchars($value);          echo "$name : $value 
\n"; } } ?>

According to register_globals settings, you can create common PHP variables from cookies. However, this feature is not recommended because this option is usually disabled for security reasons. In earlier PHP versions, when the track_vars configuration option is enabled (this option is always enabled since PHP 4.0.3), the system also sets $ HTTP_COOKIE_VARS.

 

The above is the session mechanism 1, which is characteristic of PHP. For more information about Cookie usage, see PHP Chinese website (www.php1.cn )!

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.