-2

现在我正在尝试使用 PHP 和 CURL 登录我的帐户,但我仍然不确定为什么不起作用。

我试图登录的页面是:http ://lardi-trans.com/index.jsp 脚本执行后,我在未经授权的情况下获得了相同的页面。提前致谢!

<?php


$url = "http://lardi-trans.com/log/index.jsp";
$referer = "http://lardi-trans.com/index.jsp";
$user_agent = "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:17.0) Gecko/20100101 Firefox/17.0";
$post = "action=/log/login.jsp&log=MYLOGIN&passwd=MYPASSWORD&enter=enter&onlog=%D0%92%D0%BE%D0%B9%D1%82%D0%B8";
$header [] = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header [] = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3";
$header [] = "Accept-Encoding:gzip,deflate";
$header [] = "Accept-Language:en-US,en;q=0.5";
$user_cookie = "cookies.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url ); 
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, "identity");
curl_setopt($ch, CURLOPT_COOKIEFILE, $user_cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $user_cookie);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$page = curl_exec($ch);
curl_close($ch);

echo $page;
?>
4

1 回答 1

0

您应该将 $url 变量设置为登录表单操作的值 - http://lardi-trans.com/log/login.jsp

于 2012-12-18T12:41:01.603 回答