Set and send cookies:
<? PHP $ value = "my cookie value"; // send a simple cookiesetcookie("TestCookie",$value);?> <HTML> <body> ......
<? PHP $ value = "my cookie value"; // send a cookie that expires in 24 hourssetcookie("TestCookie",$value, time()+3600*24);?> <HTML> <body> ......
Example 2
Different Methods for retrieving cookie values:
<HTML> <body> <? PHP // output individual cookieecho $ _ cookie ["testcookie"]; echo "<br/>"; echo $ http_cookie_vars ["testcookie"]; echo "<br/>"; // output all cookieprint_r ($ _ cookie);?> </Body>
Output:
my cookie valuemy cookie valueArray ([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 one hour agosetcookie ("TestCookie", "", time() - 3600);?> <HTML> <body> ......
Example 4
Create an array COOKIE:
<? PHPsetcookie("cookie[three]","cookiethree");setcookie("cookie[two]","cookietwo");setcookie("cookie[one]","cookieone");// Output cookie (after the page is reloaded) if (isset ($ _ cookie ["cookie"]) {foreach ($ _ cookie ["cookie"] as $ name = >$ value) {echo "$ name: $ value <br/>" ;}}?> <HTML> <body> ......
Output:
three : cookiethreetwo : cookietwoone : cookieone
$ _ Files get the Upload File Information egg size absolute path name
A constant is a value that cannot be modified in a program.
The define () function assigns a variable a constant. Egg define ("ABC", 123); the following code uses ABC to represent 123.
\ N escape character line feed
$ _ Cookie usage