php100学习记录32

因为62讲起涉及到的东西比较多,很多之前的东西容易忘,所以再次复习下32讲,下面是两个源文件。
index.php

<?php
if($_GET[out]){
	setcookie('id','');  //设置cookie值为空即可退出登录
	setcookie('pass','');
	echo "<script>location.href='index.php'</script>"; //非即时生效,需要刷新
 
}
 
if($_POST[iname] && $_POST[ipassword]){
	setcookie('id',$_POST[iname],time()+3600); //开始设置cookie,名称、内容、时间
	setcookie('pass',$_POST[ipassword],time()+3600);
	echo "<script>location.href='index.php'</script>"; //非即时生效,需要刷新
 
}
 
if($_COOKIE[id] && $_COOKIE[pass]){
	echo "login success<br>name:".$_COOKIE[id]."<br>pass".$_COOKIE[pass];
	echo "<a href=index.php?out=out>out</a>";
 
 
}
 
?>
<form method="post" name="myform">
<input type="text" name="iname"><br>
<input type="password" name="ipassword">
<input type="submit" value="login">
</form>

2.php

<?php
session_start(); //session_start()这个是启动必须的
 
if($_GET[out]==out){
	unset($_SESSION[id]); //销毁session
	unset($_SESSION[pass]);
	echo "退出";
 
}
 
if($_POST[iname] && $_POST[ipassword]){
$_SESSION[id]=$_POST[iname]; //开始设置session值,可对其加密
$_SESSION[pass]=$_POST[ipassword];
 
 
}
 
if($_SESSION[id] && $_SESSION[pass]){
	echo "login success<br>name:".$_SESSION[id]."<br>pass:".$_SESSION[pass]."<br>";
	echo "<a href=2.php?out=out>out</a>"; 
 
 
}
 
?>
<form method="post" name="myform">
<input type="text" name="iname"><br>
<input type="password" name="ipassword">
<input type="submit" value="login">
</form>

Related posts:

Leave a Reply

Your email address will not be published.