午夜福利院在线观看免费,天堂最新版在线,色噜噜精品一区二区三区,无码一区二区三区中文字幕,丝袜美腿一区二区三区

首頁(yè)>文檔>技術(shù)文檔>用PHP寫一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面

此組別內(nèi)的文章

需要支持?

如果通過(guò)文檔沒(méi)辦法解決您的問(wèn)題,請(qǐng)?zhí)峤还潍@取我們的支持!

用PHP寫一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面

這篇文章給大家分享的是用PHP怎樣實(shí)現(xiàn)一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,文中示例代碼介紹的非常詳細(xì),感興趣的朋友接下來(lái)一起跟隨小編看看吧。    

    PHP實(shí)現(xiàn)簡(jiǎn)單注冊(cè)登錄 詳細(xì)全部代碼 先看演示~

    示例圖:

用PHP寫一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面插圖
用PHP寫一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面插圖1

    Ps.本人有點(diǎn)懶哈~ 就輸出個(gè)成功算了吧~

用PHP寫一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面插圖2

    PHP實(shí)現(xiàn)登錄注冊(cè)

  • index.php (首頁(yè))
  • login.php (登錄)
  • register.php (注冊(cè))

    代碼里面注釋寫很詳細(xì)了哦~ 廢話不多說(shuō) 直接上代碼~

    index.php文件

    代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Zhe - 注冊(cè)登錄</title>
<link rel="stylesheet" type="text/css"  rel="external nofollow" />
<script src="https://www.layuicdn.com/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
 <legend>Zhe - 登錄注冊(cè)演示</legend>
</fieldset> 
<div style="padding: 20px; background-color: #F2F2F2;">
 <div class="layui-row layui-col-space15">
 <div class="layui-col-md6">
  <div class="layui-card">
  <div class="layui-card-header">注冊(cè)</div>
  <div class="layui-card-body">
			<form class="layui-form" action="register.php" method="post" onsubmit="return checkForm(this)" 
                        lay-filter="example">
			 <div class="layui-form-item">
			 <label class="layui-form-label">輸入框</label>
			 <div class="layui-input-block">
			  <input type="text" name="username" placeholder="請(qǐng)輸入賬號(hào)" class="layui-input">
			 </div>
			 </div>
			 <div class="layui-form-item">
			 <label class="layui-form-label">密碼框</label>
			 <div class="layui-input-block">
			  <input type="password" name="password" placeholder="請(qǐng)輸入密碼" class="layui-input">
			 </div>
			 </div>			 
			 <div class="layui-form-item">
			 <div class="layui-input-block">
			  <input type="submit" class="layui-btn layui-btn-normal" value="立即注冊(cè)"/>
			 </div>
			 </div>
			</form>
  </div>
  </div>
 </div>
 <div class="layui-col-md6">
  <div class="layui-card">
  <div class="layui-card-header">登錄</div>
  <div class="layui-card-body">
			<form class="layui-form" action="login.php" method="post" onsubmit="return checkForm(this)" 
                        lay-filter="example">
			 <div class="layui-form-item">
			 <label class="layui-form-label">輸入框</label>
			 <div class="layui-input-block">
			  <input type="text" name="username" placeholder="請(qǐng)輸入賬號(hào)" class="layui-input">
			 </div>
			 </div>
			 <div class="layui-form-item">
			 <label class="layui-form-label">密碼框</label>
			 <div class="layui-input-block">
			  <input type="password" name="password" placeholder="請(qǐng)輸入密碼" class="layui-input">
			 </div>
			 </div>			 
			 <div class="layui-form-item">
			 <div class="layui-input-block">
				 <input type="submit" class="layui-btn layui-btn-normal" value="立即登錄"/>
			 </div>
			 </div>
			</form>
  </div>
  </div>
 </div>
 </div>
</div>
<script type="text/javascript">
	// 驗(yàn)證輸入不為空的腳本代碼
	function checkForm(form) {
	if(form.username.value == "") {
	alert("用戶名不能為空!");
	form.username.focus();
	return false;
	}
	if(form.password.value == "") {
	alert("密碼不能為空!");
	form.password.focus();
	return false;
	}
	return true;
	}
</script>
</body>
</html>

    login.php文件

    代碼如下:

<?php
	session_start();
	header("content-type:text/html;charset=utf-8");
	//連接數(shù)據(jù)庫(kù)
	$link = mysqli_connect("localhost","pay_com_cn","pay_com_cn","pay_com_cn");
	if (!$link) {
		die("連接失敗: " . mysqli_connect_error());
	}
	//接收$_POST用戶名和密碼
	$username = $_POST['username'];
	$password = $_POST['password'];
	//查看表user用戶名與密碼和傳輸值是否相等
	$sql = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
	//result必需規(guī)定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的結(jié)果集標(biāo)識(shí)符。
	$result = mysqli_query($link,$sql);
	$num = mysqli_num_rows($result);//函數(shù)返回結(jié)果集中行的數(shù)量
	//判斷是否登錄后顯示或跳轉(zhuǎn)
	if($num){
		echo '登錄成功';
	}else{
		echo'登錄失敗';
	}
	mysqli_close($link);//關(guān)閉數(shù)據(jù)庫(kù)
 ?>

    register.php文件

    代碼如下:

<?php
	header("content-type:text/html;charset=utf-8");
	//連接數(shù)據(jù)庫(kù)
	$link = mysqli_connect("localhost","pay_com_cn","pay_com_cn","pay_com_cn");
	if (!$link) {
		die("連接失敗: " . mysqli_connect_error());
	}
	//接收$_POST用戶名和密碼
	$username=$_POST['username'];
	$password=$_POST['password'];
	//查看表user用戶名是否存在或?yàn)榭?	$sql_select = "SELECT * FROM user WHERE username = '$username'";
	//result必需規(guī)定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的結(jié)果集標(biāo)識(shí)符。
	$select = mysqli_query($link,$sql_select);
	$num = mysqli_num_rows($select);//函數(shù)返回結(jié)果集中行的數(shù)量
	if($username == "" || $password == "")
	{
		echo "請(qǐng)確認(rèn)信息完整性";
	}else if($num){
		echo "已存在用戶名";//已存在賬戶名輸出錯(cuò)誤
	}else{
			$sql="insert into user(username,password) values('$username','$password')";
			$result=mysqli_query($link,$sql);
			//判斷是否注冊(cè)后顯示內(nèi)容
			if(!$result)
			{
				echo "注冊(cè)不成功!"."<br>";//輸出錯(cuò)誤
				echo "<a href='index.php'>返回</a>";//超鏈接到首頁(yè)
			}
			else
			{
				echo "注冊(cè)成功!"."<br/>";//輸出成功
				echo "<a href='index.hphp'>立刻登錄</a>";//超鏈接到首頁(yè)
			}
		}
	
?>

    最后附上本文用到的mysql表

    注意先將數(shù)據(jù)庫(kù)和user表字段創(chuàng)建完成在運(yùn)行程序

用PHP寫一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面插圖3

    以上就是關(guān)于用PHP怎樣實(shí)現(xiàn)一個(gè)簡(jiǎn)易的登陸注冊(cè)頁(yè)面的介紹,上述示例具有一定的借鑒價(jià)值,有需要的朋友可以參考學(xué)習(xí),希望對(duì)大家學(xué)習(xí)PHP有幫助,想要了解更多可以繼續(xù)瀏覽群英網(wǎng)絡(luò)其他相關(guān)的文章。

0 條回復(fù) A文章作者 M管理員
    暫無(wú)討論,說(shuō)說(shuō)你的看法吧
QQ客服
  • QQ176363189 點(diǎn)擊這里給我發(fā)消息
旺旺客服
  • 速度網(wǎng)絡(luò)服務(wù)商 點(diǎn)這里給我發(fā)消息
電子郵箱
  • sudu@yunjiasu.cc
微信客服
  • suduwangluo