php注冊(cè)和登錄界面的實(shí)現(xiàn)案例(推薦)
當(dāng)初我覺(jué)得一個(gè)網(wǎng)站上注冊(cè)和登錄這兩個(gè)功能很神奇,后來(lái)自己研究一下發(fā)現(xiàn)其實(shí)道理很簡(jiǎn)單,接下來(lái)看一下怎么實(shí)現(xiàn)的吧。。。。
我在我的電腦上建了幾個(gè)文件:
login.html (登錄頁(yè)面)
register.html(注冊(cè)頁(yè)面)
success.html(登錄成功跳轉(zhuǎn)頁(yè)面)
return.html(注冊(cè)成功頁(yè)面)
login.php
register.php
登錄界面和注冊(cè)界面以及success.html并沒(méi)有
什么都是些html標(biāo)記如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>登錄界面</title> </head> <body> <form method="post" action="login.php"> 賬號(hào): <input type="text" name="usernamel"><br/><br/> 密碼: <input type="password" name="passwordl"> <input type="submit" value="登錄" name="subl"> <a >沒(méi)有賬號(hào),注冊(cè)</a> </form> </body> </html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>會(huì)員注冊(cè)</title> </head> <body> <form method="post" action="register.php"> 賬 戶(hù): <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="注冊(cè)" name="sub"> </form> </body> </html>
return.html是注冊(cè)成功之后呈現(xiàn)的頁(yè)面,里面有一段js代碼是用來(lái)定時(shí)返回登錄界面的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無(wú)標(biāo)題文檔</title>
</head>
<body>
注冊(cè)成功!<br/>
5秒后返回登錄界面<br/>
你也可以直接點(diǎn)擊回到<a >登錄頁(yè)面</a>
<script type="text/javascript">
setTimeout("ren()",5000);
function ren()
{
window.location="http://127.0.0.1:8080/login.html";
}
</script>
</body>
</html>
register.php這是與注冊(cè)頁(yè)面相對(duì)應(yīng)后臺(tái)頁(yè)面
<?php
$link=mysql_connect("localhost","root","207207");//鏈接數(shù)據(jù)庫(kù)
header("Content-type:text/html;charset=utf-8");
if($link)
{
//echo"鏈接數(shù)據(jù)庫(kù)成功";
$select=mysql_select_db("login",$link);//選擇數(shù)據(jù)庫(kù)
if($select)
{
//echo"選擇數(shù)據(jù)庫(kù)成功!";
if(isset($_POST["sub"]))
{
$name=$_POST["username"];
$password1=$_POST["password"];//獲取表單數(shù)據(jù)
$password2=$_POST["password2"];
if($name==""||$password1=="")//判斷是否填寫(xiě)
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."請(qǐng)?zhí)顚?xiě)完成!"."\"".")".";"."</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ù)庫(kù)表中是否已存在該用戶(hù)名
{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."該用戶(hù)名已被注冊(cè)"."\"".")".";"."</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"."\"".")";//將注冊(cè)信息插入數(shù)據(jù)庫(kù)表中
//echo"$sql";
mysql_query($sql,$link);
mysql_query('SET NAMES UTF8');
$close=mysql_close($link);
if($close)
{
//echo"數(shù)據(jù)庫(kù)關(guān)閉";
//echo"注冊(cè)成功!";
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>";
}
}
}
}
?>
login.php登錄界面對(duì)應(yīng)后臺(tái)文件
<?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"."("."\""."請(qǐng)?zhí)顚?xiě)正確的信息!"."\"".")".";"."</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)//判斷密碼與注冊(cè)時(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>";
}
}
}
}
?>
自己閑來(lái)無(wú)事做的還有許多要完善的地方,歡迎大家提問(wèn)討論,提供更簡(jiǎn)便的方法!
以上就是小編為大家?guī)?lái)的php注冊(cè)和登錄界面的實(shí)現(xiàn)案例(推薦)全部?jī)?nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
thinkphp3.2框架集成QRcode生成二維碼的方法分析
這篇文章主要介紹了thinkphp3.2框架集成QRcode生成二維碼的方法,結(jié)合實(shí)例形式分析了QRcode的下載、擴(kuò)展以及thinkphp3.2使用QRcode生成二維碼的相關(guān)操作技巧,需要的朋友可以參考下2020-03-03
php 在字符串指定位置插入新字符的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇php 在字符串指定位置插入新字符的簡(jiǎn)單實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06
為你的 Laravel 驗(yàn)證器加上多驗(yàn)證場(chǎng)景的實(shí)現(xiàn)
這篇文章主要介紹了為你的 Laravel 驗(yàn)證器加上多驗(yàn)證場(chǎng)景的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
PHP實(shí)現(xiàn)微信小程序人臉識(shí)別刷臉登錄功能
本文通過(guò)實(shí)例代碼給大家講解了基于PHP實(shí)現(xiàn)微信小程序人臉識(shí)別刷臉登錄功能,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-05-05
PHP實(shí)現(xiàn)linux命令tail -f
tail 命令從指定點(diǎn)開(kāi)始將文件寫(xiě)到標(biāo)準(zhǔn)輸出.使用tail命令的-f選項(xiàng)可以方便的查閱正在改變的日志文件,tail -f filename會(huì)把filename里最尾部的內(nèi)容顯示在屏幕上,并且不但刷新,使你看到最新的文件內(nèi)容.接下來(lái)通過(guò)本文給大家介紹PHP實(shí)現(xiàn)linux命令tail -f,需要的朋友參考下2016-02-02
dhtmlxTree目錄樹(shù)增加右鍵菜單以及拖拽排序的實(shí)現(xiàn)方法
本篇文章介紹了,dhtmlxTree目錄樹(shù)增加右鍵菜單以及拖拽排序的實(shí)現(xiàn)方法。需要的朋友參考下2013-04-04
PHP與Ajax相結(jié)合實(shí)現(xiàn)登錄驗(yàn)證小Demo
AJAX即“Asynchronous Javascript And XML”(異步JavaScript和XML),是指一種創(chuàng)建交互式網(wǎng)頁(yè)應(yīng)用的網(wǎng)頁(yè)開(kāi)發(fā)技術(shù)。接下來(lái)通過(guò)本文給大家分享PHP與Ajax相結(jié)合實(shí)現(xiàn)登錄驗(yàn)證小Demo,對(duì)php ajax實(shí)現(xiàn)登錄驗(yàn)證相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-03-03

