PHP:转发ntlm凭证以卷曲 [英] php: forward ntlm credentials to curl

查看:94
本文介绍了PHP:转发ntlm凭证以卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态php页面,需要使用get参数调用它。然后,我想将生成的html放入字符串中,并在以后使用(我正在尝试使用Web服务的补品框架)。

I have a dynamic php page which I need to call with a get parameter. I then want to put the generated html into a string and use it later ( I'm tryign out tonic framework for web services)

所以这类似于 PHP-将动态生成的HTML读入字符串吗? / a>,然后尝试使用cURL的答案。

So this is similar to PHP - Read dynamically generated (and echoed) HTML into a string? and I tried the answer that uses cURL.

问题是身份验证是通过ntlm(apache mod_auth_sspi)完成的。执行curl的php脚本已通过身份验证,例如,只有有效用户才能执行它。是否可以将这些凭据传递给cURL?
(用户名可用,但密码当然不可用)

The issue is that authentication is done with ntlm (apache mod_auth_sspi). The php script executing curl is already authenticated, eg only valid users can ever execute it. It is somehow possible to pass on these "credentials" to cURL? (username is available but of course not the password)

或者也可以使用完全不同的方法,但是我唯一的想法就是创建一个函数

Or a completely different approach would be fine too but only idea I had was to make a function that creates a string with html content.

$response = new Response($request);
$format = $request->mostAcceptable(array(
    'json', 'html', 'txt'
        ));

switch ($format) {

    case 'html':
        $response->addHeader('Content-type', 'text/html');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://localhost/viewRecord.php?identifier=' . $identifier);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); 
        $html = curl_exec($ch);
        curl_close($ch);
        $response->body = $html;
        break;
    //...   
}


推荐答案

答案很简单:

这是不可能的。

一种解决方法是将所有不需要目录中的文件(包括php,JavaScript和CSS)(需要php,JavaScript和CSS)。

A workaround is to put all the files (including php, JavaScript and CSS) in a directory that does not need require NTLM authentication.

要实现此目的,要么需要访问Apache配置,要么您唯一希望的就是Apache配置允许覆盖.htaccess中的SSPI。允许进行任何身份验证(也没有任何身份验证),但由于对所有请求都来自同一服务器上的cURL的限制,因此只能访问127.0.0.0。

To achieve this one either needs access to the Apache Configuration and if that is not possible only thing you can hope for is that the Apache Configuration allows overriding SSPI in .htaccess. Allow any authentication (=also none) but limit access to 127.0.0.0 since allrequest come from cURL on the same server.

要进行授权,您可以将数据放入php session将会话cookie传递到cURL,然后可以将会话数据用于从cURL调用的页面中的授权。

For authorization, you can put the data in the php session an pass the session cookie on to cURL and then the session data can be used for authorization in the page called from cURL.

编辑:

我基本上减少了NTLM的使用。我现在有1个登录页面(身份验证),其他所有内容均由php会话控制(授权)。参见

I've basically reduced NTLM usage even more. I now have 1 login page (authentication) and everything else is controlled by php session (authorization). See

Apache2, PHP:创建自动ntlm登录页面

这篇关于PHP:转发ntlm凭证以卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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