Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Logowanie CURL do https://www.allianz.ch/mednew-dmz/login
bart44
post
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 10.09.2016

Ostrzeżenie: (0%)
-----


Witam.
Aktualnie tworzę stronę mającą prezentować dane pobierane automatycznie ze stronki https://www.allianz.ch/ w formacie JSON.
Ale przed pobraniem owych danych skrypt musi zalogowac sie do https://www.allianz.ch/mednew-dmz/login.
Skrypt ma działać na współdzielonym hostingu home.pl
Nie mogę sobie poradzić z tym logowaniem, przemieliłem już xxxx tutoriali do phpCurl i nie widze efektów.
Może ktoś będzie mógł mi pomóc.
W ostateczne chaotycznej wersji doszedłem do:

CODE

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//we are going to need the length of the data string
$data_length = strlen($post_string);

$urlch = 'https://www.allianz.ch/mednew-dmz/check-login?Location=https%3A%2F%2Fwww.allianz.ch%2Fgwapps%2Frwz%2Frestwertzentrale.nsf%2FServiceAllCars.xsp%2Fjsoncars%3Flang%3Dde';
$urldata = 'https://www.allianz.ch/gwapps/rwz/restwertzentrale.nsf/ServiceCarOffer.xsp/jsoncaroffer';
$urlout='https://www.allianz.ch/mednew-dmz/logout-disclaimer?lang=de';
$urllogin='https://www.allianz.ch/mednew-dmz/login';
$urlin ='https://www.allianz.ch/gwapps/startapp/rwzwelcome.nsf/Welcome.xsp';




################################################################################
################################################################################

// Initialize cURL
$curl = curl_init('https://www.allianz.ch/gwapps/rwz/restwertzentrale.nsf/ServiceCarOffer.xsp/jsoncaroffer?lang=de');

//header('Host: https://www.allianz.ch');

################################################################################
################################################################################



// Enable Cookies
curl_setopt ($curl, CURLOPT_COOKIEFILE, './tmp/P8010365');
curl_setopt ($curl, CURLOPT_COOKIEJAR, './tmp/P8010365');
// Referer declaration
curl_setopt ($curl, CURLOPT_REFERER, $urlin);

curl_setopt ($curl,CURLOPT_HEADER, 1);
// Set POST
curl_setopt($curl, CURLOPT_POST, 1);

//header('Access-Control-Allow-Origin: *');
header('Referer:https://www.allianz.ch/gwapps/rwz/restwertzentrale.nsf/ServiceCarOffer.xsp/jsoncaroffer');

curl_setopt ($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2');
//SSL VERIFY OFF
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
// Follow server redirects.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
// NO PEAR SSL VERYFICATION

// Return output as string.
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
//Binarny transfer
//curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
// Include the header in the output.
//curl_setopt ($curl, CURLOPT_HEADER, 0);
//HTTPHEADER


//Binarny transfer
//curl_setopt($curl, CURLOPT_BINARYTRANSFER, True);





curl_setopt($curl, CURLOPT_URL, $urllogin);

// BEZ NAGŁÓWKA
// Don't include the header in the output.
//curl_setopt ($curl, CURLOPT_HEADER, 0);
// Set up post fields from login form
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);

// curl_setopt($curl, CURLOPT_POSTREDIR, 4);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
//curl_setopt($curl, CURLOPT_POST, false);
$wynik = curl_exec ($curl);
//print '<body onload="getElementById('mainform').submit();" >';
print $wynik;
header('Access-Control-Allow-Origin: *');


header('Host: www.allianz.ch');
header('Origin: htps://www.allianz.ch');
header('Referer: https://www.allianz.ch/gwapps/rwz/restwertz...caroffer');
curl_close ($curl);

print '<script type="text/javascript">';
//print 'document.getElementById("mainform").action = "";';
print 'document.getElementById("uid").value = "USERNAME";';
print 'document.getElementById("password").value = "HASŁO";';
// print 'document.getElementById("mainform").submit();';
print '</script>';
print '<script type="text/javascript">document.getElementById("mainform").submit();</script>';
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 17:20