如何为 PHP 全局设置 CURLOPT_CAINFO? [英] How can I set CURLOPT_CAINFO globally for PHP?

查看:50
本文介绍了如何为 PHP 全局设置 CURLOPT_CAINFO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在任何特定实例上设置该选项,但是我真正想要的是在 php.ini 或类似的地方设置一些东西,以便在所有项目和所有实例中处理这个问题.

I understand that I can set the option on any specific instance, however what I would really like is to set something up php.ini or somewhere similar which will handle this across all projects and all instances.

有人知道我有什么方法可以做到这一点吗?

Does anyone know a way for me to accomplish this?

我对允许证书位于不同服务器上的不同位置的解决方案特别感兴趣.

I am particularly interested in a solution which will allow for the certificates to be in different locations on different servers.

我正在一台需要它的 Windows 机器上进行开发,但部署到一个 Linux 服务器上,该服务器不仅不需要它,而且甚至没有指明路径.

I am developing on a Windows machine which needs this but deploying to a Linux server which not only doesn't need it but doesn't even have the path indicated.

我知道我可以使用条件来检查代码运行的位置,但更愿意让它开箱即用.在我看来,这确实是 curl 和 PHP 处理的问题,而不是我的代码,因此它的设置属于那里.

I understand that I can use conditions to check where the code is running but would prefer to just have it work out of the box. It seems to me that this is really an issue for curl and PHP to handle rather than my code and hence the settings for it belong there.

推荐答案

我在这里找到了答案(在用户笔记中):http://php.net/manual/en/function.curl-setopt.php

I found the answer here (in the user notes): http://php.net/manual/en/function.curl-setopt.php

只需将其添加到您的 .ini(注意:您不能使用 ini_set,尽管我不知道您为什么要这样做.谢谢@Carlton):

Just add this to you .ini (note: you cannot use ini_set, although I don't know why you would want to. Thanks @Carlton):

curl.cainfo=c:\php\cacert.pem

并从以下位置获取该文件:http://curl.haxx.se/docs/caextract.html

And get that file from: http://curl.haxx.se/docs/caextract.html

有效并且您不会为 MITM 攻击敞开心扉

Works and you aren't opening yourself up for MITM attacks

这篇关于如何为 PHP 全局设置 CURLOPT_CAINFO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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