加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php mysql 用户登录源代码

发布时间:2020-12-13 05:17:11 所属栏目:PHP教程 来源:网络整理
导读:源代码如下: 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("localh

源代码如下:

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();

}

}

?>

(编辑:李大同)

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

    推荐文章
      热点阅读