1

I'm currently making a Control Panel for my infamous Minecraft Voting System - however am running into a problem. My code works fine on XAMPP - however is not working on my webserver.

I have two pages. One is a login page, and one is an index. The login page simply gets the user info for a SQL database, and checks it, which logs the user in, and redirects using a html meta refresh, as the webserver wasn't allowing PHP headers to be used.

The index page simply says "Welcome $user,". All of this works like a charm on XAMPP, however is not working so great on my webserver. As this error crops up when logging in:

Warning: Cannot modify header information - headers already sent by (output started at /home/linkycra/public_html/MonlotronCP/login.php:3) in /home/linkycra/public_html/MonlotronCP/login.php on line 136

Here is the login.php code - http://puu.sh/1IrEu.png

Here is the index.php code - http://puu.sh/1IrF1.png

Thank you!

LegacyP7
  • 59
  • 1
  • 1
  • 11

4 Answers4

1

There must some html or white space before your header function please check it.

Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
1

You are using setcookie() AFTER you have already sent HTML to the browser. setcookie() will send an HTTP header, but will error since you have already sent HTML before the form. Reason the error only appears when you login as that is when setcookie() is triggered. You can't send a HTTP header once content has already been output to the browser.

The reason it worked on one machine and not the other is one has error_reporting on or set to display, and the other does not, or they are at different error levels. You need to restructure your code where setcookie() is run before you output any content so before <html> and <!DOCTYPE> and any empty spaces.

kittycat
  • 14,983
  • 9
  • 55
  • 80
0

check the example on this page: http://php.net/manual/en/function.headers-sent.php

It may help you track down where it's happening

Jason
  • 507
  • 3
  • 10
0

Could be solved with output buffering, if it's a typo-thing you should solve it instead though.

Niclas Larsson
  • 1,317
  • 8
  • 13