苏燕君,阿根廷杜高犬价格,保山美食
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(); } } ?>
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
YII2框架中使用RBAC对模块,控制器,方法的权限控制及规则的使用示例
YII2框架中ActiveDataProvider与GridView的配合使用操作示例
PhpStorm的使用教程(本地运行PHP+远程开发+快捷键)
网友评论