一、会话控制session、cookie

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 
 7 </head>
 8 
 9 <body>
10 <?php
11 session_start();      //在您把用户信息存储到 PHP session 中之前,首先必须启动会话。
12                            //注释:session_start()函数必须位于 <html> 标签之前:
13 $_SESSION["uid"]="123";//存储session信息,以后用户名都要用它来存储。
14 
15 $_SESSION["name"]="张三";
16 
17 echo $_SESSION["uid"];
18 //一、session、二、cookie
19 
20 //一、session 1、存储在服务器2、可以存放任何类型的数据3、有默认过期时间15分钟4、每个登录者都会存储一份
21 
22 //二、cookie 1、存储在客户端2、只能存放字符串3、默认永久的,可以设置过期时间4、客户也可以存一份
23 
24 //session用法
25 //1、可以记录登录者的状态
26 //2、可以用来在页面之间传值
27 //3、可以防止用户跳过登录
28 //4、登录传用户名,购物车,流程
29 
30 
31 ?>
32 <form  action="hhcl.php" method="post">
33 <div>用户名:<input type="text" name="aaaa" /></div>
34 
35 <div>密码:<input type="text" name="pwd" /></div>
36 <div><input type="submit" value="登录" /></div>
37 </form>
38 </body>
39 </html>
40 
41 
42 <?php
43 session_start();
44 
45 
46 $uid= $_POST["aaaa"];
47 
48 
49 //cookie存储信息
50 //setcookie("uid",$uid);
51 header("location:main.php");
52 
53 <title>无标题文档</title>
54 </head>
55 
56 <body>
57 <?php
58 session_start();
59 if(!empty($_SESSION["uid"]))
60 {
61     
62 }else
63 {
64     header($_SESSION["uid"]);
65 }
66 
67 echo $_SESSION["uid"];
68 ?>
69 
70 </body>
71 </html>

123

posted on 2016-04-18 10:35  悠悠小花  阅读(167)  评论(0编辑  收藏  举报