简体   繁体   English

file_get_contents vs cUrl。 哪个更相关,更安全?

[英]file_get_contents vs cUrl. Which is more relevant and secure?

Which would be more appropriate in terms of security? 哪个在安全方面更合适?

In case of file_get_contents(), if any error occurs, it displays the url being called in the error msg which may be vulnerable. 在file_get_contents()的情况下,如果发生任何错误,它将显示在错误消息中调用的url,该错误可能是易受攻击的。

I think curl is more secure because if you're working with remote file with file_get_contents() you need to enable 'allow_url_fopen' 我认为curl更安全,因为如果你使用file_get_contents()处理远程文件,你需要启用'allow_url_fopen'

reference : 参考:
http://25labs.com/alternative-for-file_get_contents-using-curl/ http://25labs.com/alternative-for-file_get_contents-using-curl/
http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html

And continuing discussion from the comments in the question, yes cURL give you more option and if you want to check more you can see it in the documentation here 从问题中的评论继续讨论,是的cURL为您提供了更多选项,如果您想查看更多,您可以在此处的文档中看到它
For file_get_contents() it just a simple GET request. 对于file_get_contents(),它只是一个简单的GET请求。

  • file_get_contents is only useful for GET requests file_get_contents仅对GET请求有用
  • file_get_contents needs allow_url_fopen on to access remote sources file_get_contents需要allow_url_fopen才能访问远程源

A URL can be used as a filename with this function if the fopen wrappers have been enabled. 如果已启用fopen包装器,则URL可用作此函数的文件名。 See fopen() for more details on how to specify the filename. 有关如何指定文件名的更多详细信息,请参阅fopen()。 See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. 有关各种包装器具有哪些功能的信息,使用说明以及它们可能提供的任何预定义变量的信息,请参阅支持的协议和包装器。

  • You have way more options in your request using cURL. 您可以使用cURL在请求中获得更多选项。 Take a look at setopt . 看看setopt

it displays the url being called in the error msg which may be vulnerable. 它显示在错误消息中调用的url,它可能容易受到攻击。

Turn off error reporting and ensure display_errors is deactivated. 关闭错误报告并确保取消激活display_errors。 It may also be worthwhile to create your own handler to handle errors. 创建自己的处理程序来处理错误也是值得的。

error_reporting(0);
ini_set('display_errors', 0);

file_get_content can do post by stream_context_set_option, but, i think maybe curl more powerful. file_get_content可以通过stream_context_set_option发布,但是,我想也许卷曲更强大。

ref: 参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM