溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

實現PHP的登錄和注冊的上的功能

發布時間:2020-08-10 10:52:43 來源:億速云 閱讀:192 作者:小新 欄目:開發技術

這篇文章將為大家詳細講解有關實現PHP的登錄和注冊的上的功能,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

1.新建三個html文件,兩個php文件和若干個CSS文件和若干個JS文件

2.登錄的html頁面顯示效果圖

實現PHP的登錄和注冊的上的功能

3.注冊的頁面的顯示效果圖

實現PHP的登錄和注冊的上的功能

4.登錄頁面的form表單代碼

<div class="sign-con w1200">
			<img src="img/logn-tu.gif" class="sign-contu f-l"/>
			<form action="login.php" method="post">
				<div class="sign-ipt f-l">
					<p>用戶名:</p>
					<input type="text" name="username" placeholder="手機號/郵箱" />
					<p>密碼:</p>
					<input type="password" name="password" placeholder="密碼可見" />
					<br />
					<button class="slig-btn">登錄</button>
					<p>
						沒有賬號?請
						<a href="regist.html" rel="external nofollow" >注冊</a>
						<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="wj">忘記密碼?</a>
					</p>
					<div class="sign-qx">
						<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-r">
							<img src="img/sign-xinlan.gif" />
						</a>
						<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="qq f-r">
							<img src="img/sign-qq.gif" />
						</a>
						<div ></div>
					</div>
				</div>
			</form>
			<div ></div>
		</div>

5.注冊頁面的form表單代碼

<div class="password-con registered">
			<form action="regist.php" method="post">
				<div class="psw">
					<p class="psw-p1">用戶名</p>
					<input type="text" name="username" placeholder="HR了" />
					<span class="dui"></span>
				</div>
				<div class="psw">
					<p class="psw-p1">輸入密碼</p>
					<input type="password" name="password" placeholder="請輸入密碼" />
					<span class="cuo">密碼由6-16的字母、數字、符號組成</span>
				</div>
				<div class="psw">
					<p class="psw-p1">確認密碼</p>
					<input type="password" name="repassword" placeholder="請再次輸入密碼" />
					<span class="cuo">密碼不一致,請重新輸入</span>
				</div>
				<div class="psw psw2">
					<p class="psw-p1">手機號/郵箱</p>
					<input type="text" name="telphone" placeholder="請輸入手機/郵箱驗證碼" />
					<button>獲取短信驗證碼</button>
				</div>
				<div class="psw psw3">
					<p class="psw-p1">驗證碼</p>
					<input type="text" placeholder="請輸入驗證碼" />
				</div>
				<div class="yanzhentu">
					<div class="yz-tu f-l">
						<img src="img/psw-yanzhengtu.gif" />
					</div>
					<p class="f-l">
						看不清楚?
						<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >換張圖</a>
					</p>
					<div ></div>
				</div>
				<div class="agreement">
					<input type="checkbox" name="hobby" />
					<p>
						我有閱讀并同意
						<span>《宅客微購網站服務協議》</span>
					</p>
				</div>
				<button type="submit" value="注冊" class="psw-btn">立即注冊</button>
				<p class="sign-in">
					已有賬號?請
					<a href="login.html" rel="external nofollow" >登錄</a>
				</p>
			</form>
		</div><!-- 注冊框結束 -->

6.login.php代碼

<&#63;php
  header("Content-type: text/html; charset=utf-8");
  $username = $_POST['username'];
  $password = $_POST['password'];
  $conn = new mysqli('localhost','root','root','shopping');
  if ($conn->connect_error){
    echo '數據庫連接失??!';
    exit(0);
  }else{
    if ($username == ''){
      echo '<script>alert("請輸入用戶名!");history.go(-1);</script>';
      exit(0);
    }
    if ($password == ''){
      echo '<script>alert("請輸入密碼!");history.go(-1);</script>';
      exit(0);
    }
    $sql = "select username,password from userinfo where username = '$_POST[username]' and password = '$_POST[password]'";
    $result = $conn->query($sql);
    $number = mysqli_num_rows($result);
    if ($number) {
      echo '<script>window.location="index.html";</script>';
    } else {
      echo '<script>alert("用戶名或密碼錯誤!");history.go(-1);</script>';
    }
  }
&#63;>

7.regist.php代碼

<&#63;php
  header("Content-type: text/html; charset=utf-8");
    $username = $_POST['username'];
    $password = $_POST['password'];
    $repassword = $_POST['repassword'];
    $telphone = $_POST['telphone'];
    if ($username == ''){
      echo '<script>alert("請輸入用戶名!");history.go(-1);</script>';
      exit(0);
    }
    if ($password == ''){
      echo '<script>alert("請輸入密碼");history.go(-1);</script>';
      exit(0);
    }
    if ($password != $repassword){
      echo '<script>alert("密碼與確認密碼應該一致");history.go(-1);</script>';
      exit(0);
    }
    if($password == $repassword){
      $conn = new mysqli('localhost','root','root','shopping');
      if ($conn->connect_error){
        echo '數據庫連接失??!';
        exit(0);
      }else {
        $sql = "select username from userinfo where username = '$_POST[username]'";
        $result = $conn->query($sql);
        $number = mysqli_num_rows($result);
        if ($number) {
          echo '<script>alert("用戶名已經存在");history.go(-1);</script>';
        } else {
          $sql_insert = "insert into userinfo (username,password,telphone) values('$_POST[username]','$_POST[password]','$_POST[telphone]')";
          $res_insert = $conn->query($sql_insert);
          if ($res_insert) {
            echo '<script>window.location="index.html";</script>';
          } else {
            echo "<script>alert('系統繁忙,請稍候!');</script>";
          }
        }
      }
    }else{
      echo "<script>alert('提交未成功!'); history.go(-1);</script>";
    }
&#63;>

8.進入首頁后的圖片

實現PHP的登錄和注冊的上的功能

9.數據庫的圖片

實現PHP的登錄和注冊的上的功能

關于實現PHP的登錄和注冊的上的功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女