Setcookie () usage-php Tutorial

Source: Internet
Author: User
Setcookie () usage when php assigns values to cookies. I wanted to create a function this morning. after logging on to a user, I saved the user's name to the cookie. However, I started to use the cookie reading method, but it didn't work. later I found that setcookie () was used () later, I wanted to create a function. after logging on to a user, I saved the user's name to the cookie. However, I started to use the cookie reading method, but it didn't work. later I found that setcookie () was used () it must be followed by time. I will introduce it later.

Syntax
Setcookie (name, value, expire, path, domain, secure)

Parameter description
Name is required. Specifies the cookie name.
Value is required. Specifies the cookie value.
Expire is optional. Specifies the cookie validity period.
Path is optional. Specifies the server path of the cookie.
Domain is optional. Specifies the domain name of the cookie.
Secure is optional. Specifies whether to transmit cookies through secure HTTPS connections.


For example, a simple assignment to a cookie

The code is as follows:

$ Value = "my cookie value ";

// Send a cookie that expires in 24 hours
Setcookie ("TestCookie", $ value, time () + 3600*24 );
?>


For example, store two-dimensional arrays to cookies.

A. php

The code is as follows:

$ Cart_info [0] [0] = "1123 ";
$ Cart_info [1] [0] = "5334521 ";
$ Cart_info [1] [2] = "df ";
$ Cart_info [4] [2] = "fefe ";

Setcookie ("xia", serialize ($ cart_info ));
?>

B. php

The code is as follows:

$ Other = StripSlashes ($ _ COOKIE ['Xia ']);
Print_r (unserialize ($ other ));
?>

The response method, but it didn't work. later, we found that after using setcookie...

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.