我正在尝试登录此网址:
https://epayment.bank-maskan.ir/Banking/InstallmentShetab.aspx
此页面有4个输入和一些隐藏的输入,如__viewstate。
这是我的代码:
<?php
$urlLogin = "https://epayment.bank-maskan.ir/Banking/InstallmentShetab.aspx";
$urlSecuredPage = "https://epayment.bank-maskan.ir/Banking/InstallmentShetab.aspx";
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';
// POST names and values to support login
$namefield1='ctl00$Body$PanControl$Pan1';
$namefield2='ctl00$Body$PanControl$Pan2';
$namefield3='ctl00$Body$PanControl$Pan3';
$namefield4='ctl00$Body$PanControl$Pan4';
$valfield1='6280';
$valfield2='2370';
$valfield3='3101';
$valfield4='3135';
$cookieFile = 'cookie.txt';
$regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i';
$regexEventVal = '/__EVENTVALIDATION\" value=\"(.*)\"/i';
function regexExtract($text, $regex, $nthValue)
{
$regs = Array();
if (preg_match($regex, $text, $regs)) {
$result = $regs[$nthValue];
}
else {
$result = "";
}
return $result;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlLogin);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$data=curl_exec($ch);
$viewstate = regexExtract($data,$regexViewstate,1);
$eventval = regexExtract($data, $regexEventVal,1);
$postData = '__VIEWSTATE='.$viewstate
.'&'.$namefield1.'='.$valfield1
.'&'.$namefield2.'='.$valfield2
.'&'.$namefield3.'='.$valfield3
.'&'.$namefield4.'='.$valfield4
;
curl_setOpt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_URL, $urlLogin);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$data = curl_exec($ch);
echo $data;
curl_close($ch);
?>
运行代码后这是错误:
500 - 内部服务器错误。 您正在寻找的资源存在问题,而且不能是&gt;显示。
我的代码有什么问题?