ubutu 16.04环境下,PHP与mysql数据库,网页登录验证实例讲解
(编辑:jimmy 日期: 2025/10/29 浏览:3 次 )
正好最近的域名备案通过了,兴起就突然想做一个网页,虽然之前去备案域名也是有这个目的。
问过几个人,说用linux上用PHP搭建网站很简单,就试着做了一个,这里主要说一下登录验证相关的部分;
首相准备几个文件,主要是index.php、conn.php、data.php以及login.php;
login.php 主要是登录过程中的数据对比部分;其中include ('conn.php')内容在下面有说。
<"$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';
}
"color: #ff00ff">另外要注意的是:关于$_POST针对的是form中的method =“post”中的内容。
因为里面用到MD5加密的方式,所以说一下,在后台数据库加密的时候也需要用到MD5加密的方式update数据,具体方式如下:
UPDATE USERINFO SET PASSWORD = md5('root') WHERE USERID = 1000;
其中的表格以及具体查询位置根据个人数据库而定。
conn.php 主要是跟mysql数据库连接相关的操作,分为数据库连接,以及数据库选择部分(注意数据库连接的返回值取值,不要随便起,后边引用的时候是用得着的。)
<"ok\n";
"htmlcode">
<"htmlcode">
<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">×</span></button>
<h3 class="modal-title">ログイン</h3>
</div>
<div class="modal-body">
<form class="form-signin" action="login.php" method = "post">
<h4 class="form-signin-heading">利用者名 パスワード 入力</h4>
<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"> ログイン状態を保持
</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>
基本关于登录验证部分就是这些,主要是与数据库的数据进行对比,一开始用的对称加密的方式,对加密的方式还没有仔细去研究,后面有机会再仔细看一下就好。
以上这篇ubutu 16.04环境下,PHP与mysql数据库,网页登录验证实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇:php脚本守护进程原理与实现方法详解
下一篇:thinkphp3.2实现在线留言提交验证码功能