php登入頁面cookie自動登入及驗證

來源:互聯網
上載者:User

標籤:button   admin   自動登入   roo   nbsp   from   root   html   type   

<?php
//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);


}

?>

<html>
<head>

<title>login</title>


</head>
<body>

 

<div id="wrapper">

<form name="login-form" class="login-form" action="login.php" method="post">

<div class="header">
<h1>Login Form</h1>

</div>

<div class="content">
<input name="username" type="text" class="input username" value="<?php echo $_COOKIE["username"]; ?>" />

<input name="password" type="password" class="input password" value="<?php echo $_COOKIE["password"]; ?>"/>

</div>

<div class="footer">
<input type="submit" name="submit" value="Login" class="button" />

</div>

</form>

</div>

</body>
</html>


<?php

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 "<script> window.location.href=‘http://localhost/homework/singers.php‘</script>";
}
else{
echo "<script>alert(‘you are wrong‘); window.location.href=‘http://localhost/homework/login.php‘</script>";
}

}


?>
<?php

$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);


?>

php登入頁面cookie自動登入及驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.