Hello Everyone,
This is what I want to do:
Automatically supply credentials to login to a secure webserver (basic authentication).
I already wrote some code that logs in to the secure webserver and gets the file specified. The file specified on the secure webserver contains some php code that should establish in a browser session. I can login to the server, but no browser session is created right now.
The codesnippets below do retrieve the login from the header on the secure webserver.
This is my code so far on the requesting server:
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
$login = base64_encode("user:pass");
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /sessioncreator.php HTTP/1.1\r\n"; //this file is retrieved and executed
$out .= "Host: www.example/com\r\n";
$out .= "Connection: Close\r\n";
$out .= "Authorization: Basic " . $login . "\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
<html><body><iframe src="www.example.com"></iframe></body></html><!-- this should not cause a login dialog to appear at the client -->
At the secure server this is how sessioncreator.php looks like:
<?php
session_start();
$SESSION['user'] = $SERVER['PHP_AUTH_USER'];
$SESSION['p'] = $SERVER['PHP_AUTH_PW'];
$pw = $_SERVER['PHP_AUTH_PW'];
echo "Hi $pw.<P>";
?>
Somehow this isn't sufficient to initiate a browser session between the secure server and client, if a get another page from the secure server it wants me to login again :-/
Any help would be appreciated!