开发者

PHP login form problem [duplicate]

This question already has answe开发者_开发技巧rs here: How to fix "Headers already sent" error in PHP (11 answers) Closed 10 years ago.

I created a login form on another server and it worked perfectly, now i transfered it to another server and im getting lots of new errors:

Warning: Cannot modify header information - headers already sent by (output started at /home/davethom/public_html/login.php:16) in /home/davethom/public_html/login.php on line 55

but the actual login works this message just appears, its probably just me being stupid and missing something,

www.scottechtrio.co.cc/login.html username: 1 password: 1


You are probably calling the header() function, or another function that sends headers, like setcookie(), after starting sending some output.

Those functions must be called before any output is sent to the browser :

  • Before any echo / print is done,
  • Before any character (including white-spaces) outside of <?php ... ?> tags


Check for the whitespaces in your code. Remove the php closing tags (if any) at the end of your php page.


  1. I think you need to turn off the display_errors directive in the php.ini file.
  2. If you are not able to edit php.ini file, call the following function on top of all your php files.

    ini_set('display_errors', 'Off');

You can also use .htaccess file in the webroot of your application with the following content.

php_flag   display_errors       Off


You shouldn't just turn off error reporting; you should fix your code so it doesn't cause any errors.

As stated by Pascal MARTIN, this error occurs when you call a function that sends an HTTP header after you have already sent output to the browser. session_start() sends a cookie header, so this (like header() and setcookie()) needs to be called before you output any content. Check line 55 in /home/davethom/public_html/login.php to find the offending function and make sure no content is sent to the browser before you call it.

Page content is anything sent to the browser to be rendered to the user. This could be your opening tags (or ) or even some errant whitespace, accidentally output somewhere. Look for echo or print statements, or anything not inside a set of delimiters (even just new lines or spaces here will be problematic).

As a debugging aid: to find out precisely what has been sent to the browser when this error occurs, put die(); immediately after line 55, visit the page in your browser, then use the browser to view the source it has received from the server so far.

See http://uk.php.net/manual/en/function.header.php for more information on incorrectly sending headers after content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜