Php 使用curl登录网站时出现问题

Php 使用curl登录网站时出现问题,php,curl,login,Php,Curl,Login,我需要登录到一个网站,以消除数据,但我无法登录。 下面是我的代码 我需要在其中输入值的形式 <FORM id=form1 style="BACKGROUND-COLOR: #ffffff" name=form1 action="http://120.146.143.32/cgi-bin/APWPW.EXE" method=post> <SPAN style="WIDTH: 715px; POSITION: relative; HEIGHT: 295px"> <SPA

我需要登录到一个网站,以消除数据,但我无法登录。 下面是我的代码

我需要在其中输入值的形式

<FORM id=form1 style="BACKGROUND-COLOR: #ffffff" name=form1 action="http://120.146.143.32/cgi-bin/APWPW.EXE" method=post>
<SPAN style="WIDTH: 715px; POSITION: relative; HEIGHT: 295px">
<SPAN id=text1 style="FONT-SIZE: 40px; LEFT: 130px; WIDTH: 490px; POSITION: absolute; TOP: 30px; HEIGHT: 20px">
<P>Welcome to Online Ordering</P></SPAN>
<SPAN id=text2 style="LEFT: 130px; WIDTH: 110px; POSITION: absolute; TOP: 110px; HEIGHT: 20px">
<P>Your Account #</P></SPAN>
<SPAN id=text3 style="LEFT: 130px; WIDTH: 110px; POSITION: absolute; TOP: 150px; HEIGHT: 20px">
<P>Password</P></SPAN>
<SPAN name=account style="LEFT: 260px; WIDTH: 166px; POSITION: absolute; TOP: 110px; BACKGROUND-COLOR: #ffff00"> APW146 </SPAN>
<INPUT id=password1 style="LEFT: 260px; WIDTH: 168px; POSITION: absolute; TOP: 150px; BACKGROUND-COLOR: #ffff00" type=password value="" name=password1>
<SPAN id=text4 style="LEFT: 10px; WIDTH: 300px; POSITION: absolute; TOP: 260px; HEIGHT: 20px">
<P>Keyin your Password then press enter</P></SPAN>
<INPUT id=inputimage1 style="LEFT: 460px; WIDTH: 200px; POSITION: absolute; TOP: 90px; HEIGHT: 170px" type=image src="http:/cobol/APW.JPG" name=inputimage1>
<INPUT type=hidden name=hpath value=\APW\>
<INPUT type=hidden name=haccount value=APW146>
</SPAN>
</FORM>
执行var_dump时得到的输出

array (size=22)
  'url' => string 'http://120.146.143.32/cgi-bin/APW.EXE' (length=37)
  'content_type' => string 'text/html' (length=9)
  'http_code' => int 200
  'header_size' => int 197
  'request_size' => int 226
  'filetime' => int -1
  'ssl_verify_result' => int 0
  'redirect_count' => int 0
  'total_time' => float 0.187
  'namelookup_time' => float 0
  'connect_time' => float 0.062
  'pretransfer_time' => float 0.062
  'size_upload' => float 659
  'size_download' => float 1703
  'speed_download' => float 9106
  'speed_upload' => float 3524
  'download_content_length' => float 1703
  'upload_content_length' => float 659
  'starttransfer_time' => float 0.109
  'redirect_time' => float 0
  'certinfo' => 
    array (size=0)
      empty
  'redirect_url' => string '' (length=0)
var_转储的输出($store)

string'
函数body1_onload_func()
{
if(document.form1.hbalances.value==“Y”)
document.form1.submit5.style.visibility=“可见”
其他的
document.form1.submit5.style.visibility=“隐藏”
}
函数onclick_func_b1()
{
document.form1.hchoice.value=“SA”
}
函数onclick_func_b2()
{
document.form1.hchoice.value=“OS”
}
函数oncli'。。。(长度=2710)
出于安全原因,我无法提供该帐户的密码

谢谢
Ab

服务器的实际html输出应位于以下位置:

 $store = curl_exec ($ch);

执行一个var_dump($store)并查看您得到了什么

尝试以下代码

$cookie_file_path = getcwd() . '/cookie.txt';
//Emulating Chrome Browser:
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/A.B (KHTML, like Gecko) Chrome/X.Y.Z.W Safari/A.B.";

/*  Login part of the code -- start */

//First, get and write session cookie:
$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,'http://3dstats.com/cgi-bin/edit2.cgi');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file_path);

$loginpage_html = curl_exec ($ch);

curl_close ($ch);

//Now, use the session cookie to actually log in:
$POSTFIELDS = "type=44&usr=". $your_username ."&UsrPass=". $your_password;  

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,'http://3dstats.com/cgi-bin/edit2.cgi');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, 'http://3dstats.com/cgi-bin/edit2.cgi');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file_path);

$logon_result = curl_exec ($ch);
curl_close ($ch);

请参阅详细信息

您在$user中漏掉了一个转义反斜杠
'hpath'=>'\APW\\'
应该是
'hpath'=>'\\APW\\'
另外,您遇到的确切问题是什么?“我无法登录”不是很具有描述性。你在什么地方收到错误消息了吗?我好像没有收到任何错误。但当我尝试加载我登录后可以访问的页面时,它会显示“无效帐户”。当我将密码设置错误或其他帖子参数设置错误时,会弹出此消息。我继续编辑了密码。您看到帖子中的“password1=XXXXXXX”字样了吗?那曾经是你的密码。我为你编辑了它。我在上面的问题中添加了var_dump($store)的输出。你发布到了错误的url。试着发帖子给你好,我已经试着使用这两个网址。ie既有form.php也有post.php,因为我很困惑。但结果仍然是一样的。我已经发布了所有隐藏的值并设置了cookies。奇怪的是它怎么不工作。
 $store = curl_exec ($ch);
$cookie_file_path = getcwd() . '/cookie.txt';
//Emulating Chrome Browser:
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/A.B (KHTML, like Gecko) Chrome/X.Y.Z.W Safari/A.B.";

/*  Login part of the code -- start */

//First, get and write session cookie:
$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,'http://3dstats.com/cgi-bin/edit2.cgi');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file_path);

$loginpage_html = curl_exec ($ch);

curl_close ($ch);

//Now, use the session cookie to actually log in:
$POSTFIELDS = "type=44&usr=". $your_username ."&UsrPass=". $your_password;  

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL,'http://3dstats.com/cgi-bin/edit2.cgi');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, 'http://3dstats.com/cgi-bin/edit2.cgi');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file_path);

$logon_result = curl_exec ($ch);
curl_close ($ch);