欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php+mysql實現(xiàn)簡單登錄注冊修改密碼網(wǎng)頁

 更新時間:2016年11月30日 14:32:17   作者:孤獨戰(zhàn)狼  
這篇文章主要為大家詳細介紹了php+mysql實現(xiàn)簡單登錄注冊修改密碼系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下

對于php和mysql的連接在許多blog上都有說明,為了將mysql中的查詢,修改,插入等操作掌握,本文介紹了一下如何采用mysql做一個登錄注冊修改密碼的網(wǎng)頁。

其中,如下

1.登錄-即為對數(shù)據(jù)庫中的內(nèi)容給予查詢,并驗證html中的信息與數(shù)據(jù)庫是否匹配;
2.注冊-即為對數(shù)據(jù)庫中的內(nèi)容進行插入,注冊帳號與密碼;
3.修改密碼-即為對數(shù)據(jù)庫中的內(nèi)容進行修改。

這三個操作,我用了8個php和html文本來建立 具體見代碼部分
1.登錄的主界面index.html:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>登錄注冊修改密碼系統(tǒng)主頁</title> 
<style type="text/css"> 
form { 
 text-align: center; 
} 
</style> 
</head> 
<body> 
 <form action="enter.php" method="post" onsubmit="return enter()"> 
 用戶名<input type="text" name="username" id="username"><br> 密碼<input 
 type="password" name="password" id="password"><br> <input 
 type="submit" value="登錄"> <input type="button" 
 value="注冊" onclick="register();"> 
 
 </form> 
 
 <script type="text/javascript"> 
 function enter() 
 { 
 var username=document.getElementById("username").value;//獲取form中的用戶名 
 var password=document.getElementById("password").value; 
 var regex=/^[/s]+$/;//聲明一個判斷用戶名前后是否有空格的正則表達式 
 if(regex.test(username)||username.length==0)//判定用戶名的是否前后有空格或者用戶名是否為空 
 { 
 alert("用戶名格式不對"); 
 return false; 
 } 
 if(regex.test(password)||password.length==0)//同上述內(nèi)容 
 { 
 alert("密碼格式不對"); 
 return false; 
 } 
 return true; 
 } 
 function register() 
 { 
 window.location.href="register.html";//跳轉(zhuǎn)到注冊頁面 
 } 
 </script> 
</body> 
</html> 

2.登錄的后臺操作enter.php:

<!doctype html> 
<html> 
<head> 
 <meta charset="UTF-8"> 
 <title>登錄系統(tǒng)的后臺執(zhí)行過程</title> 
</head> 
<body> 
 <?php 
 session_start();//登錄系統(tǒng)開啟一個session內(nèi)容 
 $username=$_REQUEST["username"];//獲取html中的用戶名(通過post請求) 
 $password=$_REQUEST["password"];//獲取html中的密碼(通過post請求) 
 
 $con=mysql_connect("localhost","root","root");//連接mysql 數(shù)據(jù)庫,賬戶名root ,密碼root 
 if (!$con) { 
 die('數(shù)據(jù)庫連接失敗'.$mysql_error()); 
 } 
 mysql_select_db("user_info",$con);//use user_info數(shù)據(jù)庫; 
 $dbusername=null; 
 $dbpassword=null; 
 $result=mysql_query("select * from user_info where username ='$username';");//查出對應用戶名的信息 
 while ($row=mysql_fetch_array($result)) {//while循環(huán)將$result中的結(jié)果找出來 
 $dbusername=$row["username"]; 
 $dbpassword=$row["password"]; 
 } 
 if (is_null($dbusername)) {//用戶名在數(shù)據(jù)庫中不存在時跳回index.html界面 
 ?> 
 <script type="text/javascript"> 
 alert("用戶名不存在"); 
 window.location.href="index.html"; 
 </script> 
 <?php 
 } 
 else { 
 if ($dbpassword!=$password){//當對應密碼不對時跳回index.html界面 
 ?> 
 <script type="text/javascript"> 
 alert("密碼錯誤"); 
 window.location.href="index.html"; 
 </script> 
 <?php 
 } 
 else { 
 $_SESSION["username"]=$username; 
 $_SESSION["code"]=mt_rand(0, 100000);//給session附一個隨機值,防止用戶直接通過調(diào)用界面訪問welcome.php 
 ?> 
 <script type="text/javascript"> 
 window.location.href="welcome.php"; 
 </script> 
 <?php 
 } 
 } 
 mysql_close($con);//關閉數(shù)據(jù)庫連接,如不關閉,下次連接時會出錯 
 ?> 
</body> 
</html> 

3.登錄成功后的歡迎界面welcome.php:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>歡迎登錄界面</title> 
</head> 
<body> 
 
<?php 
session_start (); 
if (isset ( $_SESSION ["code"] )) {//判斷code存不存在,如果不存在,說明異常登錄 
 ?> 
歡迎登錄<?php 
 echo "${_SESSION["username"]}";//顯示登錄用戶名 
 ?><br> 
您的ip:<?php 
 echo "${_SERVER['REMOTE_ADDR']}";//顯示ip 
 ?> 
<br> 
您的語言: 
<?php 
 echo "${_SERVER['HTTP_ACCEPT_LANGUAGE']}";//使用的語言 
 ?> 
<br> 
瀏覽器版本: 
<?php 
 echo "${_SERVER['HTTP_USER_AGENT']}";//瀏覽器版本信息 
 ?> 
<a href="exit.php">退出登錄</a> 
<?php 
} else {//code不存在,調(diào)用exit.php 退出登錄 
 ?> 
<script type="text/javascript"> 
 alert("退出登錄"); 
 window.location.href="exit.php"; 
</script> 
<?php 
} 
?> 
<br> 
 <a href="alter_password.html">修改密碼</a> 
 
</body> 
</html> 

4.修改密碼的主界面alter_password.html:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>修改密碼</title> 
<style type="text/css"> 
 form{ 
 text-align: center; 
 } 
</style> 
</head> 
<body> 
 <?php 
 session_start(); 
 ?> 
 <form action="alter_password.php" method="post" onsubmit="return alter()"> 
 用戶名<input type="text" name="username" id ="username" /><br/> 舊密碼<input 
 type="password" name="oldpassword" id ="oldpassword"/><br/> 新密碼<input 
 type="password" name="newpassword" id="newpassword"/><br/> 確認新密碼<input 
 type="password" name="assertpassword" id="assertpassword"/><br/> <input 
 type="submit" value="修改密碼" onclick="return alter()"> 
 </form> 
 <script type="text/javascript"> 
 document.getElementById("username").value="<? php echo "${_SESSION["username"]}";?>" 
 </script> 
 
 <script type="text/javascript"> 
 function alter() { 
 
 var username=document.getElementById("username").value; 
 var oldpassword=document.getElementById("oldpassword").value; 
 var newpassword=document.getElementById("newpassword").value; 
 var assertpassword=document.getElementById("assertpassword").value; 
 var regex=/^[/s]+$/; 
 if(regex.test(username)||username.length==0){ 
 alert("用戶名格式不對"); 
 return false; 
 } 
 if(regex.test(oldpassword)||oldpassword.length==0){ 
 alert("密碼格式不對"); 
 return false; 
 } 
 if(regex.test(newpassword)||newpassword.length==0) { 
 alert("新密碼格式不對"); 
 return false; 
 } 
 if (assertpassword != newpassword||assertpassword==0) { 
 alert("兩次密碼輸入不一致"); 
 return false; 
 } 
 return true; 
 
 } 
 </script> 
</body> 
</html> 

5.修改密碼的后臺操作alter_password.php:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>正在修改密碼</title> 
</head> 
<body> 
 <?php 
 session_start (); 
 $username = $_REQUEST ["username"]; 
 $oldpassword = $_REQUEST ["oldpassword"]; 
 $newpassword = $_REQUEST ["newpassword"]; 
 
 $con = mysql_connect ( "localhost", "root", "root" ); 
 if (! $con) { 
 die ( '數(shù)據(jù)庫連接失敗' . $mysql_error () ); 
 } 
 mysql_select_db ( "user_info", $con ); 
 $dbusername = null; 
 $dbpassword = null; 
 $result = mysql_query ( "select * from user_info where username ='$username';" ); 
 while ( $row = mysql_fetch_array ( $result ) ) { 
 $dbusername = $row ["username"]; 
 $dbpassword = $row ["password"]; 
 } 
 if (is_null ( $dbusername )) { 
 ?> 
 <script type="text/javascript"> 
 alert("用戶名不存在"); 
 window.location.href="alter_password.html"; 
 </script> 
 <?php 
 } 
 if ($oldpassword != $dbpassword) { 
 ?> 
 <script type="text/javascript"> 
 alert("密碼錯誤"); 
 window.location.href="alter_password.html"; 
 </script> 
 <?php 
 } 
 mysql_query ( "update user_info set password='$newpassword' where username='$username'" ) or die ( "存入數(shù)據(jù)庫失敗" . mysql_error () );//如果上述用戶名密碼判定不錯,則update進數(shù)據(jù)庫中 
 mysql_close ( $con ); 
 ?> 
 
 
 <script type="text/javascript"> 
 alert("密碼修改成功"); 
 window.location.href="index.html"; 
 </script> 
</body> 
</html> 

6.注冊帳號的主界面register.html:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>注冊系統(tǒng)</title> 
<style type="text/css"> 
form { 
 text-align: center; 
} 
</style> 
</head> 
<body> 
 
 <form action="register.php" method="post" name="form_register" 
 onsubmit="return check()"> 
 用戶名<input type="text" name="username" id="username"><br> 
 密碼<input type="password" name="password" id="password"><br> 
 確認密碼<input type="password" name="assertpassword" id="assertpassword"><br> 
 <input type="submit" value="注冊"> 
 
 </form> 
 
 <script type="text/javascript"> 
 function check() { 
 var username=document.getElementById("username").value; 
 var password=document.getElementById("password").value; 
 var assertpassword=document.getElementById("assertpassword").value; 
 var regex=/^[/s]+$/; 
 
 if(regex.test(username)||username.length==0){ 
 alert("用戶名格式不對"); 
 return false; 
 } 
 if(regex.test(password)||password.length==0){ 
 alert("密碼格式不對"); 
 return false; 
 } 
 if(password!=assertpassword){ 
 alert("兩次密碼不一致"); 
 return false; 
 } 
 } 
 </script> 
</body> 
</html> 

7.注冊帳號的后臺操作register.php:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
 <title>注冊用戶</title> 
</head> 
<body> 
 <?php 
 session_start(); 
 $username=$_REQUEST["username"]; 
 $password=$_REQUEST["password"]; 
 
 $con=mysql_connect("localhost","root","root"); 
 if (!$con) { 
 die('數(shù)據(jù)庫連接失敗'.$mysql_error()); 
 } 
 mysql_select_db("user_info",$con); 
 $dbusername=null; 
 $dbpassword=null; 
 $result=mysql_query("select * from user_info where username ='$username';"); 
 while ($row=mysql_fetch_array($result)) { 
 $dbusername=$row["username"]; 
 $dbpassword=$row["password"]; 
 } 
 if(!is_null($dbusername)){ 
 ?> 
 <script type="text/javascript"> 
 alert("用戶已存在"); 
 window.location.href="register.html"; 
 </script> 
 <?php 
 } 
 mysql_query("insert into user_info (username,password) values('$username','$password')") or die("存入數(shù)據(jù)庫失敗".mysql_error()) ; 
 mysql_close($con); 
 ?> 
 <script type="text/javascript"> 
 alert("注冊成功"); 
 window.location.href="index.html"; 
 </script> 
 
 
</body> 
</html> 

8.非法登錄時退出登錄的操作exit.php:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
</head> 
<body> 
<?php 
session_start ();//將session銷毀時調(diào)用destroy 
session_destroy (); 
?> 
<script type="text/javascript"> 
 window.location.href="index.html"; 
</script> 
</body> 
</html> 

9.mysql數(shù)據(jù)庫搭建部分

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論