//cookie实现自动登录
error_reporting(0);// 关闭错误报告(浏览页面出现notice可用此法消除)
$user = $_POST['username'];
$pwd = $_POST['password'];
if ($user!=''&&$pwd!=''){
if($_POST['remmber']==1){
header("Location:http://localhost/homework/login.php");
//转到登录页面
}
setcookie("username",$user,time()+600);//time()+600指600秒后cookie失效
setcookie("password",$pwd,time()+600);
}
?>
if(isset($_POST["username"])){//isset()判断是否为空,不空才执行,0就是空
$username=$_POST["username"];
$password=$_POST["password"];
//$submit=$_POST["submit"];
$con = mysql_connect("localhost","root","root");
if(!$con){
die("db connection is wrong:".mysql_errno());
}
mysql_select_db("db_admin",$con);
//进行输入验证
$sql1 ="select * from register where name ='".$username."'";
$str = mysql_query($sql1);
mysql_close($con);
$buffer_account="";
$buffer_pwd="";
while($user = mysql_fetch_array($str)){
$buffer_account=$user['name'];
$buffer_pwd=$user['pwd'];
}
$value1=strcmp($username,$buffer_account);
$value2=strcmp($password,$buffer_pwd);
if($value1==0&&$value2==0){
echo "";
}
else{
echo "";
}
}
?>
$con = mysql_connect("localhost","root","root");
if(!$con){
die("db connection is wrong:".mysql_errno());
}
mysql_select_db("db_admin",$con);
//把数据库里面查询的数据保存到文件里面
$sql = "select * from register";
$result = mysql_query($sql);
$data="";
while($row = mysql_fetch_row($result)){
foreach($row as $v){
$data .=$v;
}
}
file_put_contents("abc.txt",$data);
?>