0

Alright, I was not able to find a problem like mine anywhere else, so here it is.

I am using a login function to login a user. After they put their data in, I send it through the function. This then returns values based on the result, which is used by a switch to display results to the user. If they get logged in, a cookie is set in the function. The switch then uses header('Location: /') to redirect the user.

The problem with this is that when I try using Bootstrap, it throws this error:

Warning: Cannot modify header information - headers already sent by
(output started at C:\wamp\www\assets\php\header.php:89) in
C:\wamp\www\assets\classes\Shortener.php on line 163

header.php; line 89: <br/><br/><br/> (this is the end of the file)

Shortener.php (login function); line 163:

setcookie('session', $db_session_hash, time()+3600, "/");


If I remove the bootstrap parts of this, it works absolutely fine! (which angers me the most)

header.php: https://pastebin.com/jnGtHSUy

Shortener.php (login function only): https://pastebin.com/i6CG54hw

I hope this is enough information. I've been angry at this ever since I've been getting this error.

  • 1
    No point in being angry. The error indicates that somewhere in the code, some text or HTML code was set to the output stream, at which point the header is "locked". Try commenting out line 89. That is putting stuff in the stream, so when Shortener is called, output has already been written – Sparky Jun 28 '15 at 20:31
  • @Sparky I tried commenting it out, and then removing it. The error changed to line 88. It has to do something with the very last line. I have no idea why though. –  Jun 28 '15 at 20:35
  • Based on your code, comment out the ECHO commands in the PHP section. The minute not header HTML (such as your
  • tags) is written to the output stream, the header cannot be modified anymore.
  • – Sparky Jun 28 '15 at 20:36
  • 1
    possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/q/8028957) - You can *either* output HTML, *or* use a redirection header. Not both. Use one of the workarounds, or fix your processing logic. – mario Jun 28 '15 at 20:37
  • @Sparky I also did that. In fact, I removed the entire nav there and now the error was on the login page on a line that had the opening PHP tags on it. –  Jun 28 '15 at 20:41
  • I just now removed everywhere a bootstrap item was called. Ex: `col-lg-4`, and everything is working perfectly. It is something to do with Bootstrap. –  Jun 28 '15 at 20:45