AviNahum Posted October 27, 2010 Share Posted October 27, 2010 hey, i have this code: <?php //-------------------------------- // Starting our session //-------------------------------- session_start(); //-------------------------------- // load database connection //-------------------------------- require "connect.php"; //-------------------------------- // Make some checks if the admin // Are loged in //-------------------------------- if ( ! isset($_SESSION['admin']) || ! isset($_SESSION['name']) ) { require "login.php"; die(); } if ( $_SESSION['admin'] != 1 || $_SESSION['name'] == "" ) { require "login.php"; die(); } if ( $core->input['act'] == logout ) { unset($_SESSION['admin']); unset($_SESSION['name']); session_destroy(); header('Location: index.php'); } ?> im trying to set a simple session, but i getting this error: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php:1) in /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php on line 7 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php:1) in /home/rangreiss/domains/greissdesign.com/public_html/articles/admin.php on line 7 but as you can see i put the session start in the top of the file... any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/ Share on other sites More sharing options...
micah1701 Posted October 27, 2010 Share Posted October 27, 2010 what about connect.php or login.php? are they trying to call session() again? are they outputting anything? Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127195 Share on other sites More sharing options...
rwwd Posted October 27, 2010 Share Posted October 27, 2010 What is on those lines that the error references in the admin file? Also the last clause (logout) your not exiting the script after that last header call... Rw Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127196 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2010 Share Posted October 27, 2010 The OUTPUT is on line 1 of that file. Either you have an actual character in the file before the <?php tag or the output is the BOM characters that your editor saved at the start of the file. See the last post in this sticky thread - http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127198 Share on other sites More sharing options...
Lostnode Posted October 27, 2010 Share Posted October 27, 2010 What is on those lines that the error references in the admin file? Also the last clause (logout) your not exiting the script after that last header call... Rw I believe the code that aviavi has posted is the Admin file. This is usualy fixed (in my limited experience) by removing all blank lines prior to the entry: <?php //-------------------------------- // Starting our session //-------------------------------- session_start(); //-------------------------------- // load database connection //-------------------------------- require "connect.php"; This would prevent the issue that PFMaBiSmAd was talking about (the possibility of hidden characters) The other possibility is too look at the login.php and make sure it doesn't have any headers, as you have already sent them in the admin file. Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127214 Share on other sites More sharing options...
AviNahum Posted October 27, 2010 Author Share Posted October 27, 2010 the file i posted is admin.php. the login and connect files are fine... this error appeared only after i edited this file and saved it... Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127230 Share on other sites More sharing options...
BlueSkyIS Posted October 27, 2010 Share Posted October 27, 2010 hm. are you on Windows? you may have a character encoding issue and there is actually an "invisible" character before <?php Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127252 Share on other sites More sharing options...
AviNahum Posted October 28, 2010 Author Share Posted October 28, 2010 so what can i do? i wrote this file on linux but but know im on windows... Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127466 Share on other sites More sharing options...
PFMaBiSmAd Posted October 28, 2010 Share Posted October 28, 2010 If the problem are the BOM characters that your editor is placing at the start of the file, the solution is to save the file without the BOM characters. If your programming editor does not have an option to change the file encoding to UTF-8 without BOM or to ANSI encoding, you will need to use a better editor. Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127476 Share on other sites More sharing options...
AviNahum Posted October 28, 2010 Author Share Posted October 28, 2010 alright, thanks everyone... solved! Quote Link to comment https://forums.phpfreaks.com/topic/217025-session-error/#findComment-1127481 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.