如何使用file_get_contents()函数来检索后面的Windows NT验证的文件 [英] How to use file_get_contents() to retrieve a file behind Windows NT Auth

查看:211
本文介绍了如何使用file_get_contents()函数来检索后面的Windows NT验证的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其中一个LAMP服务器需要检索从坐在Windows NT身份验证背后的另一台服务器IIS的JavaScript文件输出的设置。

I've got a setup in which a LAMP server needs to retrieve an output from a javascript file from another server IIS that is sitting behind Windows NT authentication.

如果没有到位的验证,我可以只使用的file_get_contents()以检索JavaScript文件,我需要。然而,随着Windows NT身份验证的地方,失败。

Without the authentication in place, I can just use file_get_contents() to retrive the javascript file I need. However with Windows NT Authentication in place, this fails.

有没有人有任何想法我怎么能为了让PHP检索文件模拟验证过程?

Does anyone have any ideas how I can simulate the authentication process in order to allow PHP to retrieve the file?

推荐答案

使用卷曲。

function getUrl( $url, $username = false , $password = false ) {
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL, $url); 
  curl_setopt($ch, CURLOPT_HEADER, FALSE); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

  if( $username && $password ) {
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 
  }

  $buffer = curl_exec($ch); 
  curl_close($ch); 

  return $buffer;
}

这篇关于如何使用file_get_contents()函数来检索后面的Windows NT验证的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆