當前位置:學者齋 >

計算機 >php語言 >

php註冊和登入介面的實現案例

php註冊和登入介面的實現案例

當初接觸電腦程式設計的時間覺得一個網站上註冊和登入這兩個功能很神奇,後來自己研究一下發現其實道理很簡單,下面小編就為大家帶來一篇php註冊和登入介面的實現案例,感興趣的同學一起來看看怎麼實現的吧。

php註冊和登入介面的實現案例

首先在電腦上建了幾個檔案

(登入頁面)

(註冊頁面)

(登入成功跳轉頁面)

(註冊成功頁面)

登入介面和註冊介面以及並沒有

什麼都是些html標記如下:

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>登入介面</title>

</head>

<body>

<form method="post" action="">

賬號:

<input type="text" name="usernamel"><br/><br/>

密碼:

<input type="password" name="passwordl">

<input type="submit" value="登入" name="subl">

<a href="">沒有賬號,註冊</a>

</form>

</body>

</html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>會員註冊</title>

</head>

<body>

<form method="post" action="">

賬 戶:

<input type="text" name="username"><br/><br/>

密 碼:

<input type="password" name="password"><br/><br/>

密碼確認:

<input type="password" name="password2">

<input type="submit" value="註冊" name="sub">

</form>

</body>

</html>

是註冊成功之後呈現的頁面,裡面有一段js程式碼是用來定時返回登入介面的

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>無標題文件</title>

</head>

<body>

註冊成功!<br/>

5秒後返回登入介面<br/>

你也可以直接點選回到<a href="">登入頁面</a>

<script type="text/javascript">

setTimeout("ren()",5000);

function ren()

{

tion="";

}

</script>

</body>

</html>

這是與註冊頁面相對應後臺頁面

<?php

$link=mysql_connect("localhost","root","207207");//連結資料庫

header("Content-type:text/html;charset=utf-8");

if($link)

{

//echo"連結資料庫成功";

$select=mysql_select_db("login",$link);//選擇資料庫

if($select)

{

//echo"選擇資料庫成功!";

if(isset($_POST["sub"]))

{

$name=$_POST["username"];

$password1=$_POST["password"];//獲取表單資料

$password2=$_POST["password2"];

if($name==""||$password1=="")//判斷是否填寫

{

echo"<script type="."""."text/javascript".""".">"."t"."("."""."請填寫完成!".""".")".";"."</script>";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</script>";

exit;

}

if($password1==$password2)//確認密碼是否正確

{

$str="select count(*) from register where username="."'"."$name"."'";

$result=mysql_query($str,$link);

$pass=mysql_fetch_row($result);

$pa=$pass[0];

if($pa==1)//判斷資料庫表中是否已存在該使用者名稱

{

echo"<script type="."""."text/javascript".""".">"."t"."("."""."該使用者名稱已被註冊".""".")".";"."</script>";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</script>";

exit;

}

$sql="insert into register values("."""."$name".""".","."""."$password1".""".")";//將註冊資訊插入資料庫表中

//echo"$sql";

mysql_query($sql,$link);

mysql_query('SET NAMES UTF8');

$close=mysql_close($link);

if($close)

{

//echo"資料庫關閉";

//echo"註冊成功!";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</script>";

}

}

else

{

echo"<script type="."""."text/javascript".""".">"."t"."("."""."密碼不一致!".""".")".";"."</script>";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</script>";

}

}

}

}

?>

登入介面對應後臺檔案

<?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".""".">"."t"."("."""."請填寫正確的資訊!".""".")".";"."</script>";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</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)//判斷密碼與註冊時密碼是否一致

{

echo"登入成功!";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</script>";

}

{

echo"<script type="."""."text/javascript".""".">"."t"."("."""."登入失敗!".""".")".";"."</script>";

echo"<script type="."""."text/javascript".""".">"."tion=".""".""."""."</script>";

}

}

}

}

?>

以上就是小編為大家帶來的php註冊和登入介面的`實現案例全部內容了,自己閒來無事做的還有許多要完善的地方,歡迎大家提問討論,提供更簡便的方法!

標籤: PHP 介面 登入 案例
  • 文章版權屬於文章作者所有,轉載請註明 https://xuezhezhai.com/zh-tw/jsj/php/qrg5gq.html