【发布时间】:2010-09-23 07:47:02
【问题描述】:
我正在尝试使用 file_get_contents 从另一个文件中获取内容(不要问为什么)。
我有两个文件:test1.php 和 test2.php。 test1.php 根据登录的用户返回一个字符串。
test2.php 试图获取 test1.php 的内容,并被浏览器执行,从而获取 cookie。
要使用file_get_contents 发送cookie,我创建了一个流式上下文:
$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."\r\n"))`;
我正在检索内容:
$contents = file_get_contents("http://www.example.com/test1.php", false, $opts);
但现在我得到了错误:
警告:file_get_contents(http://www.example.com/test1.php) [function.file-get-contents]:打开流失败:HTTP 请求失败! HTTP/1.1 404 未找到
有人知道我在这里做错了什么吗?
编辑:
忘了提一下:没有 streaming_context,页面只会加载。但如果没有 cookie,我将无法获得所需的信息。
【问题讨论】:
-
仅供参考-如果您使用 A2hosting,则必须请求授予 fopen 访问权限(出于安全原因,他们默认将其关闭)
标签: php session cookies file-get-contents