加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php mysql 用户登录源代码

发布时间:2020-05-29 01:00:08 所属栏目:PHP 来源:互联网
导读:登录模块是网站开发中最基本最常见的模块。本文章向大家分享一个php mysql用户登录的源代码,需要的码农新手可以参考一下。

源代码如下:

function authenticate_user() {

header('WWW-Authenticate: Basic realm="Secret Stash"');

header("HTTP/1.0 401 Unauthorized");

exit;

}

if (! isset($_SERVER['PHP_AUTH_USER'])) {

authenticate_user();

} else {

mysql_pconnect("localhost","authenticator","secret") or die("Can't connect to database server!");

mysql_select_db("db") or die("Can't select authentication database!");

$query = "SELECT username,pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')";

$result = mysql_query($query);

// If nothing was found,reprompt the user for the login information.

if (mysql_num_rows($result) == 0) {

authenticate_user();

}

}

?>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读