PHP(session简单应用)

//list.php

<meta charset="UTF-8">
<?php
session_start();
//username->存储用户名
 if(@$_SESSION['username']&&@$_SESSION['username']!="")
{ 
echo"欢迎{$_SESSION['username']}<a href='break.php'/>注销</a>";
//echo $_SESSION['time'];
if($_SESSION['time']=="m")
	{ 
//利用meta
echo "<meta http-equiv='refresh' content='10; url=http://localhost/Demo2-6%20(2)/zuoye2/break.php'>";
	}

if($_SESSION['time']=="h")
	{ 
//利用meta
echo "<meta http-equiv='refresh' content='60*60; url=http://localhost/Demo2-6%20(2)/zuoye2/break.php'>";
	}

if($_SESSION['time']=="h")
	{ 
//利用meta
echo "<meta http-equiv='refresh' content='60*60*24; url=http://localhost/Demo2-6%20(2)/zuoye2/break.php'>";
	}
}
 if(!@$_SESSION['username']){ 
	echo"请先<a href='show.php'/>登录";
}
?>

//show.php

<meta charset="UTF-8">
<?php
session_start();
 if(@$_SESSION['username']&&@$_SESSION['username']!="")
{ 
header ("location:list.php");
}
if(isset($_POST['submit']))
{ 
	$username=trim($_POST['username']);
	$_SESSION['username'] = $username;
	$time=trim($_POST['time']);
	$_SESSION['time']=$time;
	if($_POST['time']=="m")
		{ 
			
             echo "缓存时长为十秒";
		}
		if($_POST['time']=="h")
		{ 
			
             echo "缓存时长为一小时";
		}
		if($_POST['time']=="d")
		{ 
			
             echo "缓存时长为一天";
		}
	echo"<script type='text/javascript'>";
	echo"alert('登录成功!');";
	echo"location.href='list.php';";
	echo"</script>";
}
?>
<html>
<head>
</head>
<body>
<form action="" method="post">
用户名:<input type='text' name="username" value=""/>
<br/>
<br/>
密码  :
<input type='password' name="password" value=""/>
<br/>
<br/>
记住登录
<select name="time">
<option value="m">10秒</option>
<option value="h">1小时</option>
<option value="d">1天</option>
</select>
<br/>
 <button type="submit"name="submit"value="登录">登录</button>
</form>
</body>
</html>

//break.php

<meta charset="UTF-8">
<?php
session_start();
 if(@$_SESSION['username']&&@$_SESSION['username']!="")
{ 
	
	session_destroy();
	echo"<script type='text/javascript'>";
	echo"alert('已注销,请重新登录!');";
	echo"location.href='list.php';";
	echo"</script>";
}
?>


你可能感兴趣的:(session判断有无字符,meta标签定时跳转)