您的位置:首页 > 其它

一、会话控制session、cookie

2016-04-18 10:35 302 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

</head>

<body>
<?php
session_start();      //在您把用户信息存储到 PHP session 中之前,首先必须启动会话。
//注释:session_start()函数必须位于 <html> 标签之前:
$_SESSION["uid"]="123";//存储session信息,以后用户名都要用它来存储。

$_SESSION["name"]="张三";

echo $_SESSION["uid"];
//一、session、二、cookie

//一、session 1、存储在服务器2、可以存放任何类型的数据3、有默认过期时间15分钟4、每个登录者都会存储一份

//二、cookie 1、存储在客户端2、只能存放字符串3、默认永久的,可以设置过期时间4、客户也可以存一份

//session用法
//1、可以记录登录者的状态
//2、可以用来在页面之间传值
//3、可以防止用户跳过登录
//4、登录传用户名,购物车,流程

?>
<form  action="hhcl.php" method="post">
<div>用户名:<input type="text" name="aaaa" /></div>

<div>密码:<input type="text" name="pwd" /></div>
<div><input type="submit" value="登录" /></div>
</form>
</body>
</html>

<?php
session_start();

$uid= $_POST["aaaa"];

//cookie存储信息
//setcookie("uid",$uid);
header("location:main.php");

<title>无标题文档</title>
</head>

<body>
<?php
session_start();
if(!empty($_SESSION["uid"]))
{

}else
{
header($_SESSION["uid"]);
}

echo $_SESSION["uid"];
?>

</body>
</html>


123
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: