求一段登录代码

ad2008 2008-04-21 05:49:36
像这样的页面:http://www.p5w.net/infoservices/grade3/wts3.htm
打开时会弹出一个框输入用户名和密码,但如果在知道用户名和密码的情况下,
如何通过PHP自动进入到这个页面呢?
...全文
110 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangbo_wb 2008-04-22
  • 打赏
  • 举报
回复
http://www.zend.com/forums/index.php?t=msg&goto=3722&S=cdb2a702c53478d2ccebe24b65e1cbe5#msg_num_1
comdeng 2008-04-21
  • 打赏
  • 举报
回复
加入用户名为username,密码为password,则需要请求的时候发送一个请求头,Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxx ,其中xxxxxxxxxxxxxxxxxxxxxxxxxxxx代表base64_encode("$username:$password") 。
在php中用curl访问该页面时,只要设置一下curl的CURLOPT_USERPWD就可以了,即curl_setopt($ch, CURLOPT_USERPWD, "$username:$password")
comdeng 2008-04-21
  • 打赏
  • 举报
回复
这是一个需要basic Authentication,即HTTP 验证的页面,一般可以这样来写:
<?php
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];

$u = "username";
$p = "password";
// HTTP Basic authorization.
if (!isset($username) || !isset($password)
|| $username != $u
|| $password != $p) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo '帐号/密码错误!';
exit;
}
?>
PleaseDoTellMeWhy 2008-04-21
  • 打赏
  • 举报
回复
关于认证的手册上就有!
fxs_2008 2008-04-21
  • 打赏
  • 举报
回复
去搜索一个cookie验证登录程序
laruence 2008-04-21
  • 打赏
  • 举报
回复
记录在Cookie,就免除了每次输入密码了

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧