fry2010 Posted February 24, 2009 Share Posted February 24, 2009 Hi I have another problem I think. I get these error messages: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\websites\bookmark.php:1) in C:\websites\bookmark.php on line 1 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\websites\bookmark.php:1) in C:\websites\bookmark.php on line 1 Now I have looked around and found that you need to put session_start(); before any headers etc so my session_start() is located here: <?php function display_header($title) { [b]session_start();[/b] ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title><?php echo $title; ?></title> </head> <body> This gets called through bookmark.php with require_once(); There is no header information going before this so I dont understand. Also it worked on my other computer before. Its really p***ing me off. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/ Share on other sites More sharing options...
revraz Posted February 24, 2009 Share Posted February 24, 2009 Move your session_start() to the top, right after <?php Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770579 Share on other sites More sharing options...
fry2010 Posted February 24, 2009 Author Share Posted February 24, 2009 thank you very much for the reply, but I tried this and didnt work. I have also placed it in the book mark before anything else. Also I have checked every included php page that there are no spaces before the <?php tag and end ?> tag. It is exactly as I had it on my other computer before that got hacked and detroyed. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770592 Share on other sites More sharing options...
revraz Posted February 24, 2009 Share Posted February 24, 2009 Then open it with notepad and see if there is either whitespace in your code or maybe a BOM. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770594 Share on other sites More sharing options...
fry2010 Posted February 24, 2009 Author Share Posted February 24, 2009 i use notepad for all code anyway. What is BOM? edit: I know that it is producing errors, but would it still not register sessions? because in my other computer i didnt have error reporting activated so I might have not noticed the warnings. It still registered sessions on that... Is there a quick way to check sessions are stored? Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770595 Share on other sites More sharing options...
fry2010 Posted February 24, 2009 Author Share Posted February 24, 2009 Ok i have checked to see if sessions are registered , and they are not. hmm.....i have no idea. very annoying when somthing works before but doesnt work now. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770612 Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2009 Share Posted February 24, 2009 What is the current error message? The error message in the first post does not match the code, so it is not possible to directly help unless both the code and matching error are posted. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770622 Share on other sites More sharing options...
fry2010 Posted February 24, 2009 Author Share Posted February 24, 2009 Ok i got rid of the first error message. i have this error message: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\websites\register.php:1) in C:\websites\output.php on line 4 here is the start of the register file: <?php require_once('bookmark.php'); $show = true; if(filled_out($_POST['register'])) { $first_name = $_POST['first_name']; $surname = $_POST['surname']; $user = $_POST['user']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $passwd1 = $_POST['passwd1']; $passwd2 = $_POST['passwd2']; here is the start of the bookmark.php file: <?php function display_header($title) { session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title><?php echo $title; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> Its all part of the same thing. Basically I have 1 php page tht includes a list of my functions. This is bookmark.php. Now in bookmark.php I have session_start(); in the function that calls the html header. Also to get rid of that first cookie error I changed something in the php ini file. I manually installed this php so it could be a problem to my ini file. Do you have to do anything with the ini file for sessions when you manually set it up? Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770633 Share on other sites More sharing options...
fry2010 Posted February 24, 2009 Author Share Posted February 24, 2009 This is friggin wierd... I have just tried to test register. I got registered and now it appears the session is stored. Yet I still get this error message. Also I cant logout because the session has not been initialised? here are the errors when I try to logout: Notice: Undefined variable: _SESSION in C:\websites\logout.php on line 4 Notice: Undefined variable: _SESSION in C:\websites\logout.php on line 5 Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\websites\logout.php on line 6 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\websites\logout.php:1) in C:\websites\output.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770640 Share on other sites More sharing options...
fry2010 Posted February 25, 2009 Author Share Posted February 25, 2009 ok even though I have this warning my sessions are still valid. So its all working now i just have an annoying warning message, either way my face looks like this Thanks to all the help. Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770682 Share on other sites More sharing options...
kenrbnsn Posted February 25, 2009 Share Posted February 25, 2009 Take the "session_start()" out of the function and put it right after the opening "<?php". Make sure there are no characters before the initial "<?php". This includes blanks. Ken Quote Link to comment https://forums.phpfreaks.com/topic/146777-solved-session_start-problem/#findComment-770784 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.