php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx

上传人:啊飒飒 文档编号:11651257 上传时间:2021-08-28 格式:DOCX 页数:6 大小:12.94KB
返回 下载 相关 举报
php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx_第1页
第1页 / 共6页
php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx_第2页
第2页 / 共6页
php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx_第3页
第3页 / 共6页
php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx_第4页
第4页 / 共6页
php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx_第5页
第5页 / 共6页
亲,该文档总共6页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx》由会员分享,可在线阅读,更多相关《php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_.docx(6页珍藏版)》请在三一文库上搜索。

1、php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证_ 本文实例讲解并描述了php用法Header函数,PHP_AUTH_PW和PHP_AUTH_USER做用户验证的方法。分享给大家供大家参考,具体如下: 在php中,可以用法Header函数做一些好玩的事情,用户验证就是其中一个很有意思的功能。具体用法: Header(-Authenticate: Basic realm=USER LOGIN); Header(HTTP/1.0 401 Unauthorized); 在页首设计这两个Header函数,页面在载入前会消失一个登录框,要求输入用户名和密码。习惯了

2、在页面登录的我们,是否觉得这样的登录很原始,又很新颖呢? 为了猎取从这个对话框中传来的用户名和密码,需要用到php供应的两个特别变量$PHP_AUTH_USER和$PHP_AUTH_PW,要这样用法这两个特别变量似乎需要在php.ini中设置相关的选项,不然就只能像下面这样引用: $_SERVERPHP_AUTH_USER $_SERVERPHP_AUTH_PW 猎取到用户提交上来的用户名和密码之后,要怎样处理规律就跟我们一般的程序处理没有什么区分了。下面供应两个例程供参考: ?php if(!isset($PHP_AUTH_USER) Header(-authenticate: basic

3、realm=XXX); Header(HTTP/1.0 401 Unauthorized); $title=Login Instructions; ? blockquote In order to enter this section of the web site, you must be an XXX subscriber. If you are a subscriber and you are having trouble logging in, please contact a href=mailto: /blockquote ?php exit; else mysql_pconnec

4、t(localhost,nobody,) or die(Unable to connect to SQL server); mysql_select_db(xxx) or die(Unable to select database); $user_id=strtolower($PHP_AUTH_USER); $password=$PHP_AUTH_PW; $query = mysql_query(select * from users where user_id=$user_id and password=$password); if(!mysql_num_rows($query) Heade

5、r(-authenticate: basic realm=XXX); Header(HTTP/1.0 401 Unauthorized); $title=Login Instructions; ? blockquote In order to enter this section of the web site, you must be an XXX subscriber. If you are a subscriber and you are having trouble logging in, please contact a href=mailto: /blockquote ?php e

6、xit; $name=mysql_result($query,0,name); $email=mysql_result($query,0,email); mysql_free_result($query); ? 另外一个参考的例程: ?php /assume user is not authenticated $auth = false; $user = $_SERVERPHP_AUTH_USER; $pass = $_SERVERPHP_AUTH_PW; if ( isset($user) isset($pass) ) /connect to db include db_connect.ph

7、p; /SQL query to find if this entered username/password is in the db $sql = SELECT * FROM healthed_workshop_admin WHERE user = $PHP_AUTH_USER AND pass = $PHP_AUTH_PW; /put the SQL command and SQL instructions into variable $result = mysql_query($sql) or die(Unable to connect.); /get number or rows i

8、n command; if more than 0, row is found $num_matches = mysql_num_rows($result); if ($num_matches !=0) /matching row found authenticates user $auth = true; if (!$auth) header(-Authenticate: Basic realm=Health Ed Presentation Admin); header(HTTP/1.0 401 Unauthorized); echo You must enter a valid username password.; exit; else echo Success!; ? 盼望本文所述对大家PHP程序设计有所关心。 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1