什么会导致curl在尝试访问本地文件时返回false? [英] what would cause curl to return false when trying to access a local file?

查看:277
本文介绍了什么会导致curl在尝试访问本地文件时返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个网站已经开了几个月了,一直工作正常。我有一个PHP页面,通过网址中的数据创建发票(例如viewinvoice.php?id = 250根据记录250构建发票)。

This site has been up for several months now and has been working fine. I have a PHP page that creates an invoice from data in the url (e.g. viewinvoice.php?id=250 builds an invoice based on record 250). This page is accessible via a web browser and works fine.

在完全不同的页面(即test.php)上,我正尝试通过cURL访问该文件。但是,当我调用和var_dump的结果,我得到bool(假)。

On a completely different page (i.e. test.php) I'm trying to access that file via cURL. However, when I make the call and var_dump the results, I get bool(false).

以下是使cURL调用的函数:

Here's the function that makes the cURL call:

function file_get_contents_curl($url) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);

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

return $data;
}

HOME是表示完整网址的常数(例如 http://www.example.com/ )。

HOME is a constant that denotes the full url (e.g. http://www.example.com/).

$invoice_contents = file_get_contents_curl(HOME.'viewinvoice.php?id=242');
echo $invoice_contents;
var_dump( $invoice_contents );

我已经尝试将url更改为外部url(即 http://www.google.com/ ),网页载入正常。我得到google的主页。但是,同一域中的任何页面将无法加载。是否有理由发生这种情况?

I've tried changing the url to an external url (i.e. http://www.google.com/) and the page loads just fine. I get google's home page. But any page that's in the same domain won't load. Is there a reason that this would happen?

我不是服务器管理员,但我有root访问服务器。我最近没有更改任何设置,但服务器管理员可能已升级apache或php的版本?

I am not the server admin, but I have root access to the server. I have not changed any settings recently, but the server admin may have upgraded the version of apache or php?

在任何情况下,是否有一个设置,我可以修改这个工作了吗?

In any case, is there a setting I can modify to make this work again?

PS

推荐答案

在curl执行之后,我们只是尝试从外部服务器,如下所示:

After your curl execution, put something like this :

echo curl_getinfo($ch) . '<br/>';
echo curl_errno($ch) . '<br/>';
echo curl_error($ch) . '<br/>';

您将看到在执行curl期间失败。

You'll see what failed during your curl execution.

更多信息: curl_getinfo curl_errno curl_error

这篇关于什么会导致curl在尝试访问本地文件时返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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