溫馨提示×

溫馨提示×

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

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

ubutu 16.04環(huán)境下,PHP與mysql數(shù)據(jù)庫實現(xiàn)網(wǎng)頁登錄驗證的方法

發(fā)布時間:2021-06-30 17:39:26 來源:億速云 閱讀:140 作者:chen 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“ubutu 16.04環(huán)境下,PHP與mysql數(shù)據(jù)庫實現(xiàn)網(wǎng)頁登錄驗證的方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“ubutu 16.04環(huán)境下,PHP與mysql數(shù)據(jù)庫實現(xiàn)網(wǎng)頁登錄驗證的方法”吧!

正好最近的域名備案通過了,興起就突然想做一個網(wǎng)頁,雖然之前去備案域名也是有這個目的。

問過幾個人,說用linux上用PHP搭建網(wǎng)站很簡單,就試著做了一個,這里主要說一下登錄驗證相關(guān)的部分;

首相準備幾個文件,主要是index.php、conn.php、data.php以及l(fā)ogin.php;

login.php 主要是登錄過程中的數(shù)據(jù)對比部分;其中include ('conn.php')內(nèi)容在下面有說。

<?php
if(!isset($_POST['submit'])){
 exit('login in error.');
}
$username = htmlspecialchars($_POST['username']);
$password = MD5($_POST['password']);
include('conn.php');
echo"$password";
$check_query = mysqli_query($result,"select USERID from USERINFO where EMAIL='$username' and PASSWORD='$password' limit 1");
if($ret = mysqli_fetch_array($check_query)){

 echo'connect true.';
}
else
{
 echo'connect false';
}
?>

另外要注意的是:關(guān)于$_POST針對的是form中的method =“post”中的內(nèi)容。

因為里面用到MD5加密的方式,所以說一下,在后臺數(shù)據(jù)庫加密的時候也需要用到MD5加密的方式update數(shù)據(jù),具體方式如下:

UPDATE USERINFO SET PASSWORD = md5('root') WHERE USERID = 1000;

其中的表格以及具體查詢位置根據(jù)個人數(shù)據(jù)庫而定。

conn.php 主要是跟mysql數(shù)據(jù)庫連接相關(guān)的操作,分為數(shù)據(jù)庫連接,以及數(shù)據(jù)庫選擇部分(注意數(shù)據(jù)庫連接的返回值取值,不要隨便起,后邊引用的時候是用得著的。)

<?php
try{
$result = mysqli_connect('localhost','root','root');
mysqli_select_db($result,'WEBDATAS');
}catch(Exception $e)
{
 echo $e->message;
 exit;
}
if(!$result)
{
 return false;
}
echo "ok\n";
?>

剩下的主要是index.php 該文件是主頁相關(guān)了,我只把登錄相關(guān)的部分拿出來說明一下(這里用到的是boostrap中的模板,有興趣的可以百度一下boostrap)

<?php
session_start();
include_once('data.php');

$handle = db_connect();
if(!$handle){
 echo 'Did not access to the database';
}else{
 echo'connect success';
}
?>

其中包含的data.php登錄部分如下:

<div class="modal fade" tabindex="-1" role="dialog" id="login">
   <div class="modal-dialog" role="document">
    <div class="modal-content">
     <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <h4 class="modal-title">ログイン</h4>
     </div>
     <div class="modal-body">
      <form class="form-signin" action="login.php" method = "post">
       <h5 class="form-signin-heading">利用者名 パスワード 入力</h5>
       <label for="inputEmail" class="sr-only">利用者名</label>
       <input type="email" name="username" id="inputEmail" class="form-control" placeholder="利用者名を入力" required autofocus>
       <label for="inputPassword" class="sr-only">パスワード</label>
       <input type="password" name="password" id="inputPassword" class="form-control" placeholder="パスワード" required>
       <div class="checkbox">
        <label>
        <input type="checkbox" value="remember-me"> ログイン狀態(tài)を保持
       </label>
       </div>
       <button class="btn btn-lg btn-primary btn-block" type="submit" name="submit">ログイン</button>
      </form>
     </div>
     <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">クローズ</button>
     </div>
    </div>
    <!-- /.modal-content -->
   </div>
   <!-- /.modal-dialog -->
  </div>

基本關(guān)于登錄驗證部分就是這些,主要是與數(shù)據(jù)庫的數(shù)據(jù)進行對比,一開始用的對稱加密的方式,對加密的方式還沒有仔細去研究,后面有機會再仔細看一下就好。

到此,相信大家對“ubutu 16.04環(huán)境下,PHP與mysql數(shù)據(jù)庫實現(xiàn)網(wǎng)頁登錄驗證的方法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI