----- 013-form.html -----
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5 <title>一个PHP网页</title> 6 </head> 7 <body> 8 <center> 9 <form action="013-cookie.php"> 10 用户名:<input type="text" name="username"/><br/> 11 密 码:<input type="text" name="password"/><br/> 12 <input type="submit" name="submit" value="登录"/> 13 <input type="reset" name="reset" value="重置"/> 14 </form> 15 </center> 16 </body> 17 </html>
----- 013-cookie.php -----
1 <?php 2 setcookie("username", $_GET[‘username‘], time()+3600); 3 setcookie("password", $_GET[‘password‘], @mktime(0,0,0,1,1,2015));//UNIX时间戳 2015.1.1过期 4 //设置Cookie前不可以传送任何一个字符甚至是一个空格 5 ?> 6 <!DOCTYPE html> 7 <html> 8 <head> 9 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 10 <title>一个PHP网页</title> 11 </head> 12 <body> 13 <?php 14 print_r($_COOKIE);echo "<br/>"; 15 print_r($_GET); 16 echo "现在的Cookie内容是:<br>"; 17 echo "用户名:", $_COOKIE[‘username‘], "<br/>"; 18 echo "密码:", $_COOKIE[‘password‘], "<br/>"; 19 ?> 20 </body> 21 </html>