session与cookie
/****************************************cookie*********************************************/
//操作
<?php
/**
* Created by PhpStorm.
* User: lzl
* Date: 2016/6/4
* Time: 15:29
*/
setcookie('a',"android"); //设置cookie
setcookie('i','iOS');
//header('Location:a.php'); //重定向
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
alert(document.cookie); //使用js获取cookie
</script>
</head>
<body>
</body>
</html>
<?php
/**
* Created by PhpStorm.
* User: lzl
* Date: 2016/6/4
* Time: 15:59
*/
echo $_COOKIE['a']; //获取cookie
<?php
/**
* Created by PhpStorm.
* User: lzl
* Date: 2016/6/4
* Time: 16:09
*/
//如果cookie被禁用了,我们还可以用其它方式来进行页面间的传值
header("Location:c.php?name=android"); //注意这里是以get方法来提交数据,所以下个页面需要用get方法来获取数据
<?php
/**
* Created by PhpStorm.
* User: lzl
* Date: 2016/6/4
* Time: 16:10
*/
echo $_GET['name']; //获取get数据
<?php
/**
* Created by PhpStorm.
* User: lzl
* Date: 2016/6/4
* Time: 16:22
*/
//session 操作
session_start(); 如果要用Session 一定要调用这个方法
//echo session_id();
session_destroy(); //销毁session
$_SESSION['name'] = 'lzl';
header("Location:s2.php");