Problem with connection to NTLM Authenticated page
Posted: Sat Oct 22, 2005 12:08 am
I need to open a connection to a NTLM Authenticated page from a php script... The problem is getting the second call through, it hangs on the first call when i am getting the file content from fgets()... her is the code so far...
Code: Select all
<?php
$url = 'skolenet.ats.dk';
$get = '/protect/ugeplan/?fn=16';
if ($fp = fsockopen($url, 80, $errno, $errstr, 30)) {
$out = "GET $get HTTP/1.1\r\n";
$out .= "Host: $url\r\n";
$out .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; da-DK; rv:1.7.12) Gecko/20050919 Firefox/1.0.7\r\n";
$out .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$out .= "Accept-Language: en-us,en;q=0.5\r\n";
$out .= "Accept-Encoding: gzip,deflate\r\n";
$out .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$out .= "Keep-Alive: 300\r\n";
$out .= "Connection: keep-alive\r\n";
$out .= "Referer: http://skolenet.ats.dk/\r\n";
$out .= "Authorization: xxx\r\n";
$out .= "\r\n";
$out2 = "GET $get HTTP/1.1\r\n";
$out2 .= "Host: $url\r\n";
$out2 .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; da-DK; rv:1.7.12) Gecko/20050919 Firefox/1.0.7\r\n";
$out2 .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'\r\n";
$out2 .= "Accept-Language: en-us,en;q=0.5\r\n";
$out2 .= "Accept-Encoding: gzip,deflate";
$out2 .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$out2 .= "Keep-Alive: 300\r\n";
$out2 .= "Connection: keep-alive\r\n";
$out2 .= "xxx\r\n";
$out2 .= "\r\n";
//step 1
echo "\n\n STEP 1 \n\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 1024);
}
fclose($fp);
$fp = fsockopen($url, 80, $errno, $errstr, 30);
//step 2
echo "\n\n STEP 2 \n\n";
fwrite($fp, $out2);
while (!feof($fp)) {
echo fgets($fp, 1024);
}
} else {
echo 'Error connection to host';
exit();
}
fclose($fp);
?>
At the moment i have removed the authentication hashes with xxx, i have recorded the hashes from a real login from firefox, but when i run the script it gets the info from the first call (step1) and hangs in the first while loop, the only way i can get it to go to step 2 is to set the connection to close, and not do a "keep-alive" connection. But if what i have read about the NTLM authentication it needs to be a keep-alive connection. ? any ideas...