Mam skrypt który ma sie logować na strone, i pobierać z niej dane.
Działał dobrze jak nie było logowania przez https, no ale niestety teraz jest i skrypt padł ;(
Nie wiecie co może być przyczyną?
Poniżej przesyłam kod:
Kod
<?
$user='xxx';
$haslo='xxx';
$config_explorer="Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8) Gecko/20051111 Firefox/1.5";
$ch = curl_init();
$file_tmp=md5(rand());
$a=fopen("tmp/$file_tmp", "w");
fclose($a);
curl_setopt($ch, CURLOPT_URL, 'https://serwer/Login.aspx');
curl_setopt($ch, CURLOPT_COOKIEJAR, "tmp/$file_tmp");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config_explorer);
$string_tmp=curl_exec ($ch);
if (curl_errno($ch)) {
echo 'Błąd #' . curl_errno($ch) . ': ' . curl_error($ch);
}
curl_close ($ch);
preg_match_all("|<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"(.*)\" \/>|U", $string_tmp, $jeden);
$viewstate=$jeden[1][0];
preg_match_all("|<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"(.*)\" \/>|U", $string_tmp, $dwa);
$eventvalidation=$dwa[1][0];
/*
// Pobieranie identyfikatora sesji ASP.NET
$plik="./tmp/$file_tmp";
$open = @fopen ($plik, "r+");
$dane = fread($open, filesize($plik));
preg_match_all("|ASP.NET_SessionId(.*)
|U", $dane, $sid);
$sesja=$sid[1][0];
$sesja=substr($sesja,0,24);
// Koniec pobierania identyfikatora sesji
*/
$ch = curl_init ();
$file_tmp_1=md5(rand());
$post_pytanie="Form1=&__VIEWSTATE=$viewstate&txtCustomerID=&txtLogin=$user&txtPassword=$haslo&ButtonLogIn=Wyślij&__EVENTVALIDATION=$eventvalidation";
curl_setopt($ch, CURLOPT_URL, 'https://serwer/Login.aspx');
curl_setopt($ch, CURLOPT_COOKIEFILE, "tmp/$file_tmp");
curl_setopt($ch, CURLOPT_COOKIEJAR, "abc");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, "https://serwer/Login.aspx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_pytanie);
curl_setopt($ch, CURLOPT_USERAGENT, $config_explorer);
if (curl_errno($ch)) {
echo 'Błąd #' . curl_errno($ch) . ': ' . curl_error($ch);
}
curl_errno($ch);
$string_tmp=curl_exec ($ch);
curl_close ($ch);
$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, "http://serwer/menuLeft.aspx");
curl_setopt($ch, CURLOPT_COOKIEFILE, "abc");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $config_explorer);
if (curl_errno($ch)) {
echo 'Błąd #' . curl_errno($ch) . ': ' . curl_error($ch);
}
echo $string_tmp=curl_exec ($ch);
curl_close ($ch);
unlink("tmp/$file_tmp");
?>
$user='xxx';
$haslo='xxx';
$config_explorer="Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8) Gecko/20051111 Firefox/1.5";
$ch = curl_init();
$file_tmp=md5(rand());
$a=fopen("tmp/$file_tmp", "w");
fclose($a);
curl_setopt($ch, CURLOPT_URL, 'https://serwer/Login.aspx');
curl_setopt($ch, CURLOPT_COOKIEJAR, "tmp/$file_tmp");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config_explorer);
$string_tmp=curl_exec ($ch);
if (curl_errno($ch)) {
echo 'Błąd #' . curl_errno($ch) . ': ' . curl_error($ch);
}
curl_close ($ch);
preg_match_all("|<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"(.*)\" \/>|U", $string_tmp, $jeden);
$viewstate=$jeden[1][0];
preg_match_all("|<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"(.*)\" \/>|U", $string_tmp, $dwa);
$eventvalidation=$dwa[1][0];
/*
// Pobieranie identyfikatora sesji ASP.NET
$plik="./tmp/$file_tmp";
$open = @fopen ($plik, "r+");
$dane = fread($open, filesize($plik));
preg_match_all("|ASP.NET_SessionId(.*)
|U", $dane, $sid);
$sesja=$sid[1][0];
$sesja=substr($sesja,0,24);
// Koniec pobierania identyfikatora sesji
*/
$ch = curl_init ();
$file_tmp_1=md5(rand());
$post_pytanie="Form1=&__VIEWSTATE=$viewstate&txtCustomerID=&txtLogin=$user&txtPassword=$haslo&ButtonLogIn=Wyślij&__EVENTVALIDATION=$eventvalidation";
curl_setopt($ch, CURLOPT_URL, 'https://serwer/Login.aspx');
curl_setopt($ch, CURLOPT_COOKIEFILE, "tmp/$file_tmp");
curl_setopt($ch, CURLOPT_COOKIEJAR, "abc");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, "https://serwer/Login.aspx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_pytanie);
curl_setopt($ch, CURLOPT_USERAGENT, $config_explorer);
if (curl_errno($ch)) {
echo 'Błąd #' . curl_errno($ch) . ': ' . curl_error($ch);
}
curl_errno($ch);
$string_tmp=curl_exec ($ch);
curl_close ($ch);
$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, "http://serwer/menuLeft.aspx");
curl_setopt($ch, CURLOPT_COOKIEFILE, "abc");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $config_explorer);
if (curl_errno($ch)) {
echo 'Błąd #' . curl_errno($ch) . ': ' . curl_error($ch);
}
echo $string_tmp=curl_exec ($ch);
curl_close ($ch);
unlink("tmp/$file_tmp");
?>
Skrypt po odpaleniu pokazuje:
Object moved to here.
Czyli tak jakby nie zapisywał cookies ;(
Z góry dzięki!
Pozdr
WeLoO