ich würde gerne den Inhalt einer Https-Seite holen, die eine Authentifizierung erfordert. Das heisst, es geht ein Browser-Popup auf, dass nach Benutzername und Passwort fragt.
Ich habe auf der PHP-Hilfe zwar einige Beispiele gefunden, aber diese funktionieren leider nicht.
Vielleicht kann mir jemand helfen, wie ich das hinbekomme?
So sieht mein bisheriges Script aus, dass bei Seiten ohne Benuzer-/Passwort-Abfrage funktioniert:
- Code: Select all
function open_https_url($url,$refer,$usecookie) {
if ($usecookie) {
if (file_exists($usecookie)) {
if (!is_writable($usecookie)) {
return "Error: Can't write to $usecookie cookie file, create an empty cookie.txt file in same folder as script";
}
} else {
$usecookie = "cookie.txt";
if (!is_writable($usecookie)) {
return "Error: Can't write to $usecookie cookie file, create an empty cookie.txt file in same folder as script";
}
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HTTPAUTH, "CURLAUTH_ANY");
curl_setopt ($ch, CURLOPT_USERPWD, "myusername:mypassword");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURL_HTTP_VERSION_1_1, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if ($usecookie) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie);
}
if ($refer != "") {
curl_setopt($ch, CURLOPT_REFERER, $refer );
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec ($ch);
$info = curl_getinfo($ch);
if ($result === false || $info['http_code'] != 200) {
$result = "Error: No cURL data returned for $url [". $info['http_code']. "]";
if (curl_error($ch)) {
$result .= "\n". curl_error($ch);
}
}
curl_close ($ch);
return $result;
}
$dateiurl = "https://myserver.com/info/abfrage?OpenAgent&test1&test2&test3";
$datei = open_https_url($dateiurl,"",true);
print $datei;