Hi.
i'm trying to login to an asp login page via php and curl...
i wrote this code by google help. i expect see originale login page whith invalid username and password message , but i see only 'Object moved to here.' error.
<?php
$urlLogin = "http://xxxx/LoginPage.aspx";
$nameUsername='txtUsername';
$namePassword='txtPassword';
$valUsername ='ivalid_username';
$valPassword ='invalid_password';
$cookieFile = 'cookie.txt';
$regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i';
$regexEventVal = '/__EVENTVALIDATION\" value=\"(.*)\"/i';
function regexExtract($text, $regex, $regs, $nthValue)
{
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_UNRESTRICTED_AUTH, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data=curl_exec($ch);
$viewstate = regexExtract($data,$regexViewstate,$regs,1);
$eventval = regexExtract($data, $regexEventVal,$regs,1);
$postData = '__VIEWSTATE='.$viewstate.'&__EVENTVALIDATION='.$eventval.'&'.$nameUsername.'='.$valUsername.'&'.$namePassword.'='.$valPassword;
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_HTTPGET, FALSE);
$data = curl_exec($ch);
echo $data;
//curl_setOpt($ch, CURLOPT_POST, FALSE);
//curl_setopt($ch, CURLOPT_URL, $urlSecuredPage);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
//$data = curl_exec($ch);
//echo $data;
curl_close($ch);
?>
i think the problem cause is curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
, i cant use it , because gives me this warning : 'Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir...'
please say me where is my mistake. thanks in advance for help.