1

This is not a duplicate, my question is specifically about the br tag, not the 'headers already sent' error.

I have a PHP redirect setup to redirect users who are not logged in to the login page, this is creating a "cannot modify header information" error because for some reason a
is on line 1 of the source code (when viewing source in browser) but I have no idea why!

The source code for the index.php is below:

<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/webuser/public_html/beta/admin/index.php:1) in       
<b>/home/webuser/public_html/beta/admin/inc/header.php</b> on line <b>3</b>    
<br />

The code for the index.php is below, I deleted everything except what is below from the page to ensure it wasn't anything on that page.:

<?
include "inc/header.php";
?>

The code for the header.php is below, I deleted everything except what is below from the page to ensure it wasn't anything on that page.:

  <?
  if ($login == 0) {
  header ("location:login?error[]=You must login to view this page!");
  }
  ?>

As you can see, the br tag isn't anywhere on my header.php or index.php so I have no idea where it is coming from. Even weirder, the header.php is included in my other pages and they do not experience the issue. Plus, once logged in, the issue isn't there and the br tag doesn't exist.

Any ideas?

EDIT: I have now deleted everything from the index.php page and ONLY had the following:

<?php header("location:login?error[]=You must login to view this page!"); ?>

Issue still occurs. No idea why. Created a new page and done the exact same, issue didn't occur.

EDIT 2: Issue is now RESOLVED. No idea what it was, I copied the content of index.php, deleted the file, created a new index.php, pasted the content back in and the error did not occur. Very weird indeed.

  • Is this WordPress? If you are using WordPress themes, I've seen functions within the functions.php that add `
    ` conditionally based certain content types being written out. Look for perhaps `echo
    ` or similar.
    – Alexander Staroselsky Jul 13 '15 at 19:56
  • Trying using the full ` – Marshall Davis Jul 13 '15 at 19:58
  • @AlexanderStaroselsky This is not wordpress, the code I have in my question is the ONLY code on the pages in question, the rest I removed to ensure it was not causing the issue. I done a full search for
    and
    with no results.
    – user3207807 Jul 13 '15 at 20:08
  • @ToothlessRebel Have just tried that, issue still occurs. – user3207807 Jul 13 '15 at 20:08
  • do you have a blank line before or after your or ?> tags? – fbas Jul 13 '15 at 19:55
  • I have a blank line after, I use the Atom editor which seems to automatically put one at the end. Hasn't caused issues before though. – user3207807 Jul 13 '15 at 20:10
  • Had the same phantom issue with a one line header redirect with no space before or after. Deleting the file and re-creating it solved the issue. In my case, the file was an index.html file that I had converted to php – chris Sep 11 '21 at 13:47

1 Answers1

0

try to remove and code, or html or any space above,

 <?php
  if ($login == 0) {
  header ("location:login?error[]=You must login to view this page!");
  }
 ?>
  • The code I have in my question is the ONLY code on the pages in question, the rest I removed to ensure it was not causing the issue. There is no additional code or space besides what I mentioned before. – user3207807 Jul 13 '15 at 20:09
  • as per the error, that you have mentioned, there can be only the reason, that there is output to the browser before the header statement, try to figure out, may be an extra line,

    tag etc...

    –  Jul 13 '15 at 20:19
  • index.php : http://prntscr.com/7sav6r header.php http://prntscr.com/7sav2h As you can see, there really isn't anything else. – user3207807 Jul 13 '15 at 20:24