【发布时间】:2012-12-13 03:40:15
【问题描述】:
我打赌它最终会变得很简单......但我可以用一只手来发现它。
问题:
当我尝试通过file_get_contents() 获取特定本地 URL 的内容时,它以空字符串 '' (length=0) 的形式返回。
我的尝试:
$url = 'http://localhost/bbq/index.php/company/get/id/2131/return/json';
$results = file_get_contents($url);
echo'<pre>Results:<br />',var_export($results),'</pre>';
当直接访问http://localhost/bbq/index.php/company/get/id/2131/return/json时,一切都美妙地回响:{"id":"2131","value":"Acme Anvil Corp."}
为了检查自己,我尝试了 $url = 'http://www.google.com',它按预期工作,所以我尝试了一个单独的本地 uri,http://localhost/?phpinfo=1,它也工作了 > 很好。
问题:
我错过了什么???
[附加信息]allow_url_fopen 已开启
我可能刚刚发现一些东西。
作为 CODEIGNITER 项目中的一项安全措施,控制器脚本的第一行有:
if ( !defined('BASEPATH')) exit('No direct script access allowed');
将其注释掉并没有带来任何改进,但我认为仍然值得一提。
此外,这里是 HTTP 响应标头的转储。也许有人可以看到那里的东西。这一切对我来说似乎很简单,但我真的不知道我应该寻找什么。
array (size=13)
0 => string 'HTTP/1.1 200 OK' (length=15)
1 => string 'Date: Thu, 27 Dec 2012 19:58:47 GMT' (length=35)
2 => string 'Server: Apache/2.4.2 (Win64) PHP/5.4.3' (length=38)
3 => string 'X-Powered-By: PHP/5.4.3' (length=23)
4 => string 'Set-Cookie: csrf_cookie_name=4ae46f9a7e612ae22a080a4e88bd349c; expires=Thu, 27-Dec-2012 21:58:47 GMT; path=/' (length=108)
5 => string 'Set-Cookie: PHPSESSID=ah70p0ldl5qptcauei1t8ihud3; path=/' (length=56)
6 => string 'Expires: Thu, 19 Nov 1981 08:52:00 GMT' (length=38)
7 => string 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0' (length=77)
8 => string 'Pragma: no-cache' (length=16)
9 => string 'Refresh: 0;url=http://localhost/bbq/index.php/index.php/user/login' (length=66)
10 => string 'Content-Length: 0' (length=17)
11 => string 'Connection: close' (length=17)
12 => string 'Content-Type: text/html' (length=23)
[/附加信息]
顺便说一句,我正在跑步:
- Win7 64 上的 WAMPSERVER
- Apache 2.4.2
- PHP 5.4.3
- CodeIgniter 2.1.2
【问题讨论】:
-
print_r($http_response_header);可能会告诉您为什么它没有响应 -
allow_url_fopensetting 是否启用? -
把“localhost”换成127.0.0.1能用吗?
-
在这里抓住稻草,但尝试附加 /?到您的原始网址。
-
究竟返回了什么???确切地? Empty 不是有效的 PHP 值。是
FALSE吗?真的是NULL吗?它是什么?var_dump对此有何评论?你为什么不直接提供你收集的调试输出和你的问题?
标签: php codeigniter httpresponse file-get-contents