我可以使用CURL与PHP中的IIS Windows身份验证绕过用户名/ PW吗?

时间:2014-05-07 15:49:31

标签: php curl windows-authentication

我正在制作一个php登录包装页面来使用AD凭证。

我尝试使用curl发布NTLM auth并使用我自己的username:password这不应该是实用的。

我当前的代码看起来像这样,现在可以使用了。因为它位于同一个域中,所以我应该能够绕过CURLOPT_USERPWD部分并摆脱$username$password

有谁能建议我怎么做?

<?php
$userName=$_SERVER['AUTH_USER'];
$userPassword=$userName;
$fields = array(
   "txtUserName" => "$userName",
   "txtPassword" => "$userPassword",
   "btn_login"=>'1'
);
//init curl function
$ch = curl_init();
$url='http://example.com/index.php';
$username="*****";
$password="*****";

// Enable HTTP POST
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1;         Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)");
curl_setopt ($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt ($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec($ch);
print_r($output);
curl_close ($ch);
?>

0 个答案:

没有答案