【问题标题】:Add header("HTTP/1.1 404 Not Found"); to PHP page with no products添加标头("HTTP/1.1 404 Not Found");到没有产品的 PHP 页面
【发布时间】:2016-02-18 14:58:48
【问题描述】:

我正在尝试将 header("HTTP/1.1 404 Not Found"); 添加到以下 PHP 中,以便没有任何产品的页面显示为未找到。

if(@$usecsslayout) print '<div class="' . $cs . 'products">';
$totrows=ect_num_rows($allprods);
if(ect_num_rows($allprods)==0)
    print (! @$usecsslayout ? '<tr><td colspan="' . $productcolumns . '" align="center">' : '') . '<p>'.$GLOBALS['xxNoPrds'].'</p>' . (! @$usecsslayout ? '</td></tr>' : '');
else while($rs=ect_fetch_assoc($allprods)){

我在if(ect_num_rows($allprods)==0)之后的各个地方添加了header("HTTP/1.1 404 Not Found");,文件挂了。

如果我将打印元素 (print (! @$usecsslayout ? '&lt;tr&gt;&lt;td colspan="' . $productcolumns . '" align="center"&gt;' : '') . '&lt;p&gt;'.$GLOBALS['xxNoPrds'].'&lt;/p&gt;' . (! @$usecsslayout ? '&lt;/td&gt;&lt;/tr&gt;' : '');) 替换为 header("HTTP/1.1 404 Not Found");,则会生成 Not Found。

我的问题是我想要一个 Not Found 与 print 语句相结合。

【问题讨论】:

    标签: php


    【解决方案1】:

    使用header 时,在调用header 之前不允许有任何输出。 print '&lt;div class="' . $cs . 'products"&gt;'; 被输出,因此标题功能不起作用。

    您将无法先打印 div 然后显示 404

    【讨论】:

    • 好的。如果这不可能,我该如何让它重定向到 404.php。
    • 没有任何输出。在调用header 函数之前,请确保没有任何输出(printecho
    • 我同意了,但它返回 302.if(ect_num_rows($allprods)==0) header("Location:/"); else while($rs=ect_fetch_assoc($allprods)){ 现在我要把它设为 301 吗?
    猜你喜欢
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 2015-01-04
    • 2021-03-07
    • 2017-06-19
    • 1970-01-01
    相关资源
    最近更新 更多