mOr*_*off 5 php codeigniter httpresponse file-get-contents
我打赌它最终会变得简单......但是我可以用它来发现它.
问题:
当我尝试获取特定本地URL的内容时file_get_contents(),它会以空字符串''(长度= 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>';
Run Code Online (Sandbox Code Playgroud)
直接访问时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');
Run Code Online (Sandbox Code Playgroud)
评论它没有提供任何改进,但我认为值得一提.
此外,这是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)
Run Code Online (Sandbox Code Playgroud)
[/附加信息]
顺便说一下,我正在运行:
立即开始调试:
# we want text output for debugging. Either this works or you need to look into
# source in your browser (or even better, debug with the `curl` commandline client.)
header('Content-Type: text/plain');
# For quick and dirty debugging - start to tell about if something is worth
# to warn or notice about. (do logging in production)
error_reporting(~0); ini_set('display_errors', 1);
$url = 'http://localhost/bbq/company/get/id/2131/return/json';
$results = file_get_contents($url);
var_dump($http_response_header, $results);
# hard exit, flush all (potential) buffers.
die();
Run Code Online (Sandbox Code Playgroud)
现在,对文件的请求必须至少为您提供一些文本输出,因为var_dump.您还可以在标题调用下方的开头添加一些标记输出,因此很明显脚本已被调用并且确实已开始运行.
但是,更好的变体是使用步调试器并使用断点创建调试会话.我推荐Xdebug.