0

我有以下代码可以登录到远程网站。

执行脚本后,我从网站收到以下错误: 技术错误 这是我执行 curl 得到的结果。

$username = $_POST['search']; $password = $_POST['pasword']; $ch = curl_init(); $postdata="&search=".$username."&password=".$password; curl_setopt ($ch, CURLOPT_URL,"https://payment.schibsted.no/login?client_id=5087dc1b421c7a0b79000000&response_type=code&redirect_uri=https%3A%2F%2Fwww.finn.no%2Ffinn%2FloginCallback%3FredirectKey%3D977170356717"); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_HEADER, true); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); curl_setopt ($ch, CURLOPT_REFERER, "https://payment.schibsted.no/login?client_id=5087dc1b421c7a0b79000000&response_type=code&redirect_uri=https%3A%2F%2Fwww.finn.no%2Ffinn%2FloginCallback%3FredirectKey%3D977170356717"); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, "menu link") ; $result2 = curl_exec($ch) ; echo $result2 ; curl_close($ch);

4

1 回答 1

0

我清理了没有换行符的代码,并使其在某种程度上更易于理解。

//Variables
$username = $_POST['search'];
$password = $_POST['pasword'];
$cookie = $username.'.txt';
$postdata = "search=${username}&password=${password}";
$agent = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)';

//*not sure if all this is needed and I don't know why you set it as the referer*
$url = 'https://payment.schibsted.no/login?client_id=5087dc1b421c7a0b79000000&response_type=code&redirect_uri=https%3A%2F%2Fwww.finn.no%2Ffinn%2FloginCallback%3FredirectKey%3D977170356717';
// ---


//Curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
curl_close($ch);
// ---

echo $result;

//*Not sure what this is doing I found it at the bottom of your code*
//curl_setopt($ch, CURLOPT_URL, "menu link");
//$result2 = curl_exec($ch) ;
//echo $result2;

我认为这一切都不是必需的,您能否提供更多信息?

于 2013-10-20T08:01:32.813 回答