In many landing interface will have a week-free function, the principle of implementation is, the option to login-free in front of the Web page as a checkbox, after the user select a post to send to the server, the server through Setcookie this function, set the client cookie variables, effective time.
Definitions and Usage
The Setcookie () function sends an HTTP cookie to the client.
A cookie is a variable that is sent by the server to the browser. Cookies are usually small text files that the server embeds into the user's computer. This cookie is sent whenever the computer requests a page through the browser.
The name of the cookie is specified as a variable of the same name. For example, if the cookie being sent is named "name", a variable named $user is automatically created, containing the value of the cookie.
The cookie must be assigned before any other output is sent. If successful, the function returns True, otherwise it returns false
<?php
$value = "my cookie value";
Send a cookie
setcookie ("TestCookie", $value, Time () +3600*24) that expired when you were 24.
>
Different ways to retrieve cookie values:
Output:
My cookie value i
cookie value
Array ([TestCookie] => my cookie value)
Example 3
Delete a cookie by setting the expiration date to the past date/time:
<?php
///Set the expiration date to
Setcookie ("TestCookie", "", Time ()-3600).
>
Example 4
Create an array cookie:
<?php
Setcookie ("Cookie[three]", "Cookiethree");
Setcookie ("Cookie[two]", "cookietwo");
Setcookie ("Cookie[one]", "Cookieone");
Output cookie (after overloaded page)
if (isset ($_cookie["Cookie"))
{
foreach ($_cookie["Cookie"] as $name => $value) c7/>{
echo "$name: $value <br/>";
}
? >
Output:
Three:cookiethree
two:cookietwo
one:cookieone