复制代码 代码如下:
<form action="login.php" method="post">
用户名<input type="text"><br>
密码<input type="text"><br>
记住密码<input type="checkbox" value="1"><br>
<input type="submit">
</form>
<a href="userinfo.php">用户信息</a>
<?php
session_start();
function p($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
p($_SESSION);
p($_COOKIE);
?>
复制代码 代码如下:
<?php
function p($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
session_start();
//p($_POST);
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
if($_POST['jizhu']){
setcookie('username',$_POST['username'],time()+60);
setcookie('password',$_POST['password'],time()+60);
}
header("location:form.php");
复制代码 代码如下:
<?php
session_start();
echo "先关闭浏览器,在访问form.php 试试,然后 点推出在关闭浏览器试试";
p($_SESSION);
p($_COOKIE);
if(empty($_SESSION['username'])){
if(empty($_COOKIE['username'])){
echo "<a href='form.php'>请先登录</a>";exit;
}else{
$_SESSION['username'] = $_COOKIE['username'];
}
}
function p($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
?>
2131231231
<a href="updateuserinfo.php">修改信息</a>
<a href="logout.php">推出</a>
复制代码 代码如下:
<?php
session_start();
unset($_SESSION['username']);
unset($_SESSION['password']);
setcookie('username','',0);
setcookie('password','',0);
header("location:form.php");
?>
复制代码 代码如下:
<?php
session_start();
if(empty($_SESSION['username'])){
echo "请先登录";
}else{
echo "这里是信息";
}
?>
新闻热点
疑难解答