《PHP實(shí)戰(zhàn):php注冊和登錄界面的實(shí)現(xiàn)案例(推薦)》要點(diǎn):
本文介紹了PHP實(shí)戰(zhàn):php注冊和登錄界面的實(shí)現(xiàn)案例(推薦),希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP實(shí)戰(zhàn)當(dāng)初我覺得一個(gè)網(wǎng)站上注冊和登錄這兩個(gè)功能很神奇,后來自己研究一下發(fā)現(xiàn)其實(shí)道理很簡單,接下來看一下怎么實(shí)現(xiàn)的吧....
PHP實(shí)戰(zhàn)我在我的電腦上建了幾個(gè)文件:
PHP實(shí)戰(zhàn)login.html (登錄頁面)
PHP實(shí)戰(zhàn)register.html(注冊頁面)
PHP實(shí)戰(zhàn)success.html(登錄成功跳轉(zhuǎn)頁面)
PHP實(shí)戰(zhàn)return.html(注冊成功頁面)
PHP實(shí)戰(zhàn)login.php
PHP實(shí)戰(zhàn)register.php
PHP實(shí)戰(zhàn)登錄界面和注冊界面以及success.html并沒有
PHP實(shí)戰(zhàn)什么都是些html標(biāo)記如下:
PHP實(shí)戰(zhàn)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登錄界面</title>
</head>
<body>
<form method="post" action="login.php">
賬號:
<input type="text" name="usernamel"><br/><br/>
密碼:
<input type="password" name="passwordl">
<input type="submit" value="登錄" name="subl">
<a >沒有賬號,注冊</a>
</form>
</body>
</html>
PHP實(shí)戰(zhàn)?
PHP實(shí)戰(zhàn)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>會員注冊</title>
</head>
<body>
<form method="post" action="register.php">
賬??戶:
<input type="text" name="username"><br/><br/>
密??碼:
<input type="password" name="password"><br/><br/>
密碼確認(rèn):
<input type="password" name="password2">
<input type="submit" value="注冊" name="sub">
</form>
</body>
</html>
PHP實(shí)戰(zhàn)return.html是注冊成功之后呈現(xiàn)的頁面,里面有一段js代碼是用來定時(shí)返回登錄界面的
PHP實(shí)戰(zhàn)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標(biāo)題文檔</title>
</head>
<body>
注冊成功!<br/>
5秒后返回登錄界面<br/>
你也可以直接點(diǎn)擊回到<a >登錄頁面</a>
<script type="text/javascript">
setTimeout("ren()",5000);
function ren()
{
window.location="http://127.0.0.1:8080/login.html";
}
</script>
</body>
</html>
PHP實(shí)戰(zhàn)register.php這是與注冊頁面相對應(yīng)后臺頁面
PHP實(shí)戰(zhàn)
<?php
$link=mysql_connect("localhost","root","207207");//鏈接數(shù)據(jù)庫
header("Content-type:text/html;charset=utf-8");
if($link)
{
//echo"鏈接數(shù)據(jù)庫成功";
$select=mysql_select_db("login",$link);//選擇數(shù)據(jù)庫
if($select)
{
//echo"選擇數(shù)據(jù)庫成功!";
if(isset($_POST["sub"]))
{
$name=$_POST["username"];
$password1=$_POST["password"];//獲取表單數(shù)據(jù)
$password2=$_POST["password2"];
if($name==""||$password1=="")//判斷是否填寫
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."請?zhí)顚懲瓿?"."\"".")".";"."</script>";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/register.html"."\""."</script>";
exit;
}
if($password1==$password2)//確認(rèn)密碼是否正確
{
$str="select count(*) from register where username="."'"."$name"."'";
$result=mysql_query($str,$link);
$pass=mysql_fetch_row($result);
$pa=$pass[0];
if($pa==1)//判斷數(shù)據(jù)庫表中是否已存在該用戶名
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."該用戶名已被注冊"."\"".")".";"."</script>";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/register.html"."\""."</script>";
exit;
}
$sql="insert into register values("."\""."$name"."\"".","."\""."$password1"."\"".")";//將注冊信息插入數(shù)據(jù)庫表中
//echo"$sql";
mysql_query($sql,$link);
mysql_query('SET NAMES UTF8');
$close=mysql_close($link);
if($close)
{
//echo"數(shù)據(jù)庫關(guān)閉";
//echo"注冊成功!";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/return.html"."\""."</script>";
}
}
else
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."密碼不一致!"."\"".")".";"."</script>";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/register.html"."\""."</script>";
}
}
}
}
?>
PHP實(shí)戰(zhàn)login.php登錄界面對應(yīng)后臺文件
PHP實(shí)戰(zhàn)
<?php
header("Content-type:text/html;charset=utf-8");
$link=mysql_connect("localhost","root","207207");
if($link)
{
$select=mysql_select_db("login",$link);
if($select)
{
if(isset($_POST["subl"]))
{
$name=$_POST["usernamel"];
$password=$_POST["passwordl"];
if($name==""||$password=="")//判斷是否為空
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."請?zhí)顚懻_的信息!"."\"".")".";"."</script>";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/login.html"."\""."</script>";
exit;
}
$str="select password from register where username="."'"."$name"."'";
mysql_query('SET NAMES UTF8');20 $result=mysql_query($str,$link);
$pass=mysql_fetch_row($result);
$pa=$pass[0];
if($pa==$password)//判斷密碼與注冊時(shí)密碼是否一致
{
echo"登錄成功!";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/success.html"."\""."</script>";
}
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."登錄失敗!"."\"".")".";"."</script>";
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/login.html"."\""."</script>";
}
}
}
}
?>
PHP實(shí)戰(zhàn)自己閑來無事做的還有許多要完善的地方,歡迎大家提問討論,提供更簡便的方法!
PHP實(shí)戰(zhàn)以上就是小編為大家?guī)淼膒hp注冊和登錄界面的實(shí)現(xiàn)案例(推薦)全部內(nèi)容了,希望大家多多支持維易PHP~
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/2961.html