Ich weiß, dass diese Frage schon oft im Stack-Overflow gestellt wurde, aber keine der Antworten löste mein Problem.Wie man Sitzung mit curl php aufrechterhält?
ich ein PHP-Skript schreibe, die curl verwendet, um remote JSP Website durchsuchen: hier ist mein Code:
<?php
$loginUrl = 'http://ccc.hyundai-motor.com/servlet/ccc.login.CccLoginServlet';
$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SHARE, $sh);
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'the post data including my username and password and other hidden fields');
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_SHARE, $sh);
curl_setopt($ch2, CURLOPT_URL,'http://ccc.hyundai-motor.com/servlet/ccc/admin/user/UserInfoServlet?cmd=myUserInfo');
curl_setopt($ch2, CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch2, CURLOPT_VERBOSE, true);
$result = curl_exec($ch2);
print $result;
curl_share_close($sh);
curl_close($ch);
curl_close($ch2);
?>
Wenn ich den Code der Cookie-Datei erstellt ausführen, aber ich erhalte eine Fehlermeldung „Session verloren Bitte loggen Sie sich erneut ein ".
http://stackoverflow.com/questions/13020404/keeping-session-alive-with-curl-and-php#13020494 – JustOnUnderMillions
Ich habe schon gelesen, dass Frage vor, aber nichts Neues, können Sie genauer über das Problem meines Codes sein? –
Thing sollten Sie nur einen dieser 'CURLOPT_COOKIEJAR | CURLOPT_COOKIEFILE'' CURLOPT_COOKIEJAR' im ersten Aufruf und 'CURLOPT_COOKIEFILE' im zweiten Teil http://stackoverflow.com/a/13020460/4916265 – JustOnUnderMillions