您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php实现网页安全认证的代码详解

2025/3/31 6:15:11发布23次查看
这篇文章主要介绍了php网页安全认证的实例详解的相关资料,这里提供了两种实现方法,一种基于数据库另一种不基于数据库的方法,希望通过本能帮助到大家,需要的朋友可以参考下
php网页安全认证的实例详解
 不基于数据库:
<?php //unset($_server['php_auth_user']); $strauthuser= $_server['php_auth_user']; $strauthpass= $_server['php_auth_pw']; if (! ($strauthuser == "a" && $strauthpass == "a")) { header('www-authenticate: basic realm="wly"'); header('http/1.0 401 unauthorized'); echo "用户验证!!"; exit; } else { echo "验证通过"; header("location:http://www.baidu.com"); //unset($_server['php_auth_user']); } ?>
基于数据库:
<?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("localhost","authenticator","secret") or die("can't connect to database server!"); mysql_select_db("java2s") 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(); } } ?>
以上就是php实现网页安全认证的代码详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product