jomofee Posted August 4, 2009 Share Posted August 4, 2009 Hello, first time poster here. I will try my best to not infringe on board rules, but if I do please realize it was a sincere accident. Thanks. The problem: I have two computers. One is a windows vista based laptop that is running wamp. The other is a linux desktop set up for amp. I transferred the files from a project I've been working from the laptop on over to the linux desktop and while the session worked fine on the laptop it isn't working on the desktop. Making matters more confusing, on my desktop I have a test I did implementing sessions and it is working fine. So on my desktop I have the one I brought over from the laptop that isn't working and yet I can get my test session to work correctly on the exact same machine. Here is the code for my index.php file which is erring out. Note: this is at the very top of the file. There is nothing before it so this should be the first code that executes. <?php session_start(); if (!isset($_SESSION['username'])) { $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\')) { $url = substr($url, 0, -1); } $url .= '/login.php'; header("Location: $url"); exit(); } Here is the code from the index.php file of my test session which is running fine. Again, this is at the very top of the file and no code is before it. <?php session_start(); if (!isset($_SESSION['username'])) { $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\')) { $url = substr($url, 0, -1); } $url .= '/login.php'; header("Location: $url"); exit(); } I am very confused by this. The error message I get from the first index.php file is- Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/development/rene/index.php:1) in /var/www/development/rene/index.php on line 3 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/development/rene/index.php:1) in /var/www/development/rene/index.php on line 3 Warning: Cannot modify header information - headers already sent by (output started at /var/www/development/rene/index.php:1) in /var/www/development/rene/index.php on line 12 I was thinking that maybe my test session's cookie was keeping my project in development from executing it's cookie correctly so I flushed all my cookies. I also went in through terminal and deleted the session info in var/lib/php5. Then I tried to run it and I still am getting the error. Another thing to keep in mind is that my project works fine on the laptop and I even drug the test session files over to see if they would work and they did. So I've got both to work on my wamp, but I can't get the project to work on the lamp even though the test session does work. I referenced both phpinfo pages on each system and there are a couple differences, but nothing significant under sessions. The solution: Any ideas? Thanks for any and all replies. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2009 Share Posted August 4, 2009 output started at /var/www/development/rene/index.php:1 (line 1) Your files have been saved as Unicode/UTF-8 and the BOM (search if you don't know what that means) that your editor (a Windows only problem) places at the start of the file is the output that is preventing the headers from working. Save your files without the BOM. You probably have output_buffering turned ON (or set to a specific size) in the php.ini where the code works. Quote Link to comment Share on other sites More sharing options...
jomofee Posted August 5, 2009 Author Share Posted August 5, 2009 Thank you so much. I use Geany in Linux as my code editor and under Documents there is a option for Write Unicode BOM on or off. It was on. I selected off. Presto. Also, for anyone needing this solution in the future, you can use Notepad++ on Windows- select menu option Format and then Unicode without BOM. I had done quite a bit of searching on this and nothing pointed me to the BOM problem. Thanks again and you rock! Quote Link to comment 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.