0

I'm trying to add header("HTTP/1.1 404 Not Found"); to the following PHP so that pages without any products show as Not Found.

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)){

I have added header("HTTP/1.1 404 Not Found"); in various places after if(ect_num_rows($allprods)==0) and the file hangs.

If I replace the print element (print (! @$usecsslayout ? '<tr><td colspan="' . $productcolumns . '" align="center">' : '') . '<p>'.$GLOBALS['xxNoPrds'].'</p>' . (! @$usecsslayout ? '</td></tr>' : '');) with header("HTTP/1.1 404 Not Found"); then a Not Found is generated.

My problem is that I want a Not Found combined with the print statement.

Sanjuktha
  • 1,065
  • 3
  • 13
  • 26

1 Answers1

0

When using header you are not allowed to have any output before the header is called. print '<div class="' . $cs . 'products">'; is output and therefor, the header function is not working.

You won't be able to first print the div and then display a 404

AgeDeO
  • 3,137
  • 2
  • 25
  • 57
  • Okay. If that's not possible how do I get it to redirect to 404.php instead. – user3138407 Nov 17 '15 at 10:28
  • Without any output. Make sure you do not have any output (`print`, `echo`) before you call the `header` function – AgeDeO Nov 17 '15 at 10:35
  • I gone with this but it returns a 302.if(ect_num_rows($allprods)==0) header("Location:/"); else while($rs=ect_fetch_assoc($allprods)){ Now do I make it a 301? – user3138407 Nov 17 '15 at 14:30