This is a learning note taken by a friend while learning php. Its function is to set the cookie and then deregister and output the cookie value.
The setcookie () function is used to set the cookie.
Note: The setcookie () function must be located before the
Syntax
Setcookie (name, value, expire, path, domain );
See the instance below
The Code is as follows: |
Copy code |
<? Php // Cancel the cookie If (isset ($ _ GET ['out']) { Setcookie ('us ',""); Echo "<script> location. href = 'index. php' </script> "; }
// Set cookie If (isset ($ _ POST ['sub']) { Setcookie ("us", $ _ POST ['user'], time () + 3600 ); Echo "<script> location. href = 'index. php' </script> "; } // Output and deregister cookies If ($ _ COOKIE ['us']) { Echo $ _ COOKIE ['us']; Echo "<a href = 'index. php? Out = out'> cancel cookies </a> "; } ?> <Form method = "post"> <Input type = "text" name = "user"> <Input type = "password" name = "pass"> <Input type = "submit" name = "sub" value = "submit"> </Form> |