论坛地址:http://www.cgjyw.cn/Forum/Default.asp
用户名:素颜格格
密码:111111我想用curl远程登陆,可是怎么也实现不了。恳请高手指点。$login_url = 'http://www.cgjyw.cn/Forum/login.asp';
$source_url = 'http://www.cgjyw.cn/Forum/Default.asp';$post_fields = array();
//以下两项不需要修改
$post_fields['menu'] = 'add';
//$post_fields['ReturnUrl'] = 'http://www.cgjyw.cn/Forum/login.asp';//用户名和密码,必须填写
$post_fields['UserName'] = '素颜格格';
$post_fields['UserPassword'] = '111111';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt($ch, CURLOPT_REFERER, $source_url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$contents = curl_exec($ch);
curl_close($ch);
echo strip_tags($contents );
用户名:素颜格格
密码:111111我想用curl远程登陆,可是怎么也实现不了。恳请高手指点。$login_url = 'http://www.cgjyw.cn/Forum/login.asp';
$source_url = 'http://www.cgjyw.cn/Forum/Default.asp';$post_fields = array();
//以下两项不需要修改
$post_fields['menu'] = 'add';
//$post_fields['ReturnUrl'] = 'http://www.cgjyw.cn/Forum/login.asp';//用户名和密码,必须填写
$post_fields['UserName'] = '素颜格格';
$post_fields['UserPassword'] = '111111';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt($ch, CURLOPT_REFERER, $source_url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$contents = curl_exec($ch);
curl_close($ch);
echo strip_tags($contents );
在连接 “login.asp” 得到的返回内容是: <script language="JavaScript" type="text/javascript">
alert('用户名没有输入');
window.history.back();
</script>也就是说POST的内容,login.asp并没有接收到。
怎么会事情呢
下面是bbsxp login.asp的源码<!-- #include file="Setup.asp" -->
<!-- #include file="API_Request.asp" -->
<%if Request("menu")="OUT" then
HtmlTop
if ReturnUrl="" and Http_Referer<>"" then ReturnUrl=Http_Referer
if ReturnUrl="" then ReturnUrl="Default.asp"
if Request_Method <> "POST" then error("<li>提交方式错误!</li><li>您本次使用的是"&Request_Method&"提交方式!</li>")
TempUserName=CookieUserName
UserLoginOut
'-------------------- API Start --------------------
If SiteConfig("APIEnable")=1 Then
Dim ApiSaveCookie
APIUserLoginOut()
End If
'-------------------- API End ----------------------
TempUserName=""
succeed "已经成功退出",ReturnUrl
elseif Request_Method = "POST" then
ReturnUrl=Request.Form("ReturnUrl")
UserName=HTMLEncode(Request.Form("UserName"))
UserPassword=Trim(Request.Form("UserPassword"))
IsMD5=False if SiteConfig("EnableAntiSpamTextGenerateForLogin")=1 then
if Request.Form("VerifyCode")<>Session("VerifyCode") or Session("VerifyCode")="" then
AlertForModal("验证码错误!")
else
Session("VerifyCode")=""
end if
end if
if UserName=empty then AlertForModal("用户名没有输入")
if UserPassword=empty then AlertForModal("密码没有输入")
if instr(UserName,"&")>0 and instr(UserName,";")>0 then AlertForModal("由于系统升级,您的用户名中含有特殊字符,请使用Email方式登录")
Invisible=Request("Invisible") if Request("IsSave")="1" then
Expired=9999
else
Expired=0
end if
Dim Message
if UserLogin=True then
'-------------------- API Start --------------------
If SiteConfig("APIEnable")=1 Then
APIUserLogin()
End If
'-------------------- API End ----------------------
else
AlertForModal(Message)
end if
%>
<script language="javascript" type="text/javascript">
<%if ReturnUrl<>"" then%>
window.location.href = "<%=ReturnUrl%>";
<%else%>
if(top == self){window.location.href = "Default.asp";}else{parent.window.location.reload();}
<%end if%>
</script>
<%
else
Response.Clear()
%>
<title>用户登录</title>
<script language="javascript" type="text/javascript">if(top == self)window.location.href = "Default.asp";</script>
<script src="Utility/global.js" type="text/javascript"></script>
<style type="text/css">body,table{font-size:9pt;}</style><form action="Login.asp" method="POST" name="form">
<table cellspacing="1" cellpadding="2" width="100%">
<tr>
<td width="30%" align="right">用户名称:</td>
<td>
<input type="text" name="UserName" value="用户名/电子邮件地址" onblur="if (this.value==''){ this.value='用户名/电子邮件地址';this.style.color='#999';}else{this.style.color='';}" onfocus="if (this.value=='用户名/电子邮件地址') {this.value='';this.style.color='';}" title="用户名/电子邮件地址" style="width:150px; color:#999" /> <a href="javascript:parent.window.location.href='CreateUser.asp';">没有注册?</a>
</td>
</tr>
<tr>
<td width="30%" align="right">用户密码:</td>
<td>
<input type="password" name="UserPassword" style="width:150px" /> <a href="javascript:parent.window.location.href='RecoverPassword.asp';">找回密码?</a>
</td>
</tr>
<%if SiteConfig("EnableAntiSpamTextGenerateForLogin")=1 then%>
<tr>
<td width="30%" align="right">验 证 码:</td>
<td>
<input type="text" name="VerifyCode" maxlength="4" size="10" onBlur="CheckVerifyCode(this.value)" onKeyUp="if (this.value.length == 4)CheckVerifyCode(this.value)" onfocus="getVerifyCode()" /> <span id="VerifyCodeImgID">点击输入框获取验证码</span> <span id="CheckVerifyCode" style="color:red"></span>
</td>
</tr>
<%end if%>
<tr>
<td align="right" width="30%">登录方式:</td>
<td>
<input type="checkbox" value="1" name="IsSave" id="IsSave" /><label for="IsSave">自动登录</label>
<input type="checkbox" value="1" name="Invisible" id="Invisible" /><label for="Invisible">隐身登录</label>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value=" 登录 " /> <input type="button" onclick="javascript:parent.BBSXP_Modal.Close();" value=" 取 消 " />
</td>
</tr>
</table>
</form>
<%
end if
%>
因为username都没有传过去呢,抓那cookie有啥用呢。事实上我把 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
加进去也没用。
依然提示:
<script language="JavaScript" type="text/javascript">
alert('用户名没有输入');window.history.back();</script>
万分感谢!!!!!!!!!!!!!!!!!!!给分结贴