【发布时间】:2010-11-10 06:17:14
【问题描述】:
我在处理服务器返回的 curl 和标头时遇到了一些问题。
1) 我在 my_website.com/index.php 上的 php 文件如下所示(精简版):
<?php
$url = 'http://my_content_server.com/index.php';
//Open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
echo $result;
?>
my_content_server.com/index.php 上的 php 文件如下所示:
<?php
header("HTTP/1.0 404 Not Found - Archive Empty");
echo "Some content > 600 words to make chrome/IE happy......";
?>
我希望当我访问 my_website.com/index.php 时,我应该得到一个 404,但这并没有发生。
我做错了什么?
2) 基本上我想要实现的是:
my_content_server.com/index.php 将决定内容类型并发送适当的标头,而 my_website.com/index.php 应该只向浏览器发送相同的内容类型和其他标头(连同实际数据)。但似乎 my_website.com/index.php 正在编写自己的标题? (或者也许我不理解正确的工作方式)。
问候, JP
【问题讨论】:
-
header('HTTP/1.0 404 Not Found - Archive Empty'); exit; -
如果是最后一条语句,退出是否重要? (我想我可以在发送 404 标头后回显?)。
-
我猜你想从my_content_server.com/index.php返回标题?
... ob_start(); $header = obj_get_contents()// your header; ob_end_clean(); header($header); echo "additional message";并使用@stillstanding 建议的curl_setopt($ch,CURLOPT_HEADER,true); -
是的,404之后可以回显任何东西。很多漂亮的404页面都是这样完成的。
标签: php curl http-headers