belmon Posted July 22, 2011 Share Posted July 22, 2011 Hi, I newly have installed apache 2.2 / php 5.2 / mysql 5.5 / phpmyadmin 3.4 on XP Home. Problem: Warning: Cannot modify header information - headers already sent by ( Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent ( .... I tried to unactivate error reports in php.ini but I just get a blank page. The problem is that it can't accept session and header. And the problem is NOT free spaces and the like. The program works just fine on the server, but not on my localhost. I've read and followed many guides about how to configure php.ini and httpd.conf. One time I installed the same and it worked; but I reinstalled OS and these programs again and this time with problem. I appreciate any help Thanks Nick Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/ Share on other sites More sharing options...
gristoi Posted July 22, 2011 Share Posted July 22, 2011 this is nothing to do with your localhost not being able to accept sessions. this error : Warning: Cannot modify header information - headers already sent by ..... means that somewhere in your code you are trying to send a header AFTER something has been sent to the page. There are two basic rules for using headers : [*]Ensure thats there is no whitespace directly after the opening / closing tags [*]Ensure that nothing is printed to the page before any kind of header redirect etc. to help you further we need to see some code Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/#findComment-1246094 Share on other sites More sharing options...
belmon Posted July 22, 2011 Author Share Posted July 22, 2011 Thanks for your answer. As I said this code already was at the server and works at it does. 1. The first alternativ can not be the case. The code is: <?php if (!isSet($pwd) || empty($pwd)) { header ( "Location: /francais/index.php " ); } else { include "db.php"; $sql = mysql_query("select * FROM user WHERE pwd = '$pwd'", $conn); while ($rs= mysql_fetch_array($sql)){ $pass = $rs['pwd']; $userid = $rs['user_id']; $nom = $rs['nom']; session_start(); session_register("pass"); session_register("nom"); session_register("userid"); } if ($pass) { header ( "Location: /francais/insert_phrase.php" ); } else { header ( "Location: /francais/index.php" ); } } ?> Hope it's more clear what I mean.. Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/#findComment-1246109 Share on other sites More sharing options...
gristoi Posted July 22, 2011 Share Posted July 22, 2011 what is in db.php ? Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/#findComment-1246116 Share on other sites More sharing options...
belmon Posted July 22, 2011 Author Share Posted July 22, 2011 YES! your are write! The space was "hidden" in my include file "db.php". Thanks alot! Nick Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/#findComment-1246117 Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2011 Share Posted July 22, 2011 @belmon, the error message you were getting, but which you did not post entirely, stated where the output was occurring at. Had you posted it or read that part of it, you would have directly known that the output was occurring in your db.php file. Just because you have php code that 'works' on one server, does not mean that it will work on all server configurations. Php has a few got ya's that hide problems in your code, so if you get errors when moving code between servers, you have to consider that the code really does have a problem in it that needs to be fixed. In most of these cases, once you correct the problem that is causing the error message, that portion of the code will work on all server configurations. Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/#findComment-1246141 Share on other sites More sharing options...
belmon Posted July 22, 2011 Author Share Posted July 22, 2011 Yes. Simple fact. But you should experience it in order to understand it. With this explanation, PFMaBiSmAd, I realize that I need to review my codes during 11 years. I'm almost sure that I would have difficulty to open at least half of them on this local server! I allways have developed and uploaded directly on the server. I think that I need to come back soon for further issus. Thanks again PFMaBiSmAd and gristoi. Nick Quote Link to comment https://forums.phpfreaks.com/topic/242624-my-localhost-cant-accept-session-and-header-in-php-pages/#findComment-1246203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.