zamp0e Posted May 28, 2009 Share Posted May 28, 2009 Hello, I have small problem with my session_start() it seems, here are the first 18 lines of code: <?php $host = "*******"; $user = "******"; $pass = "******"; $db = "******"; $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); $query = "SELECT * FROM ******"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); session_start(); include("login.php"); ?> I get two errors when I open this file in the browser: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\test\index.php:1) in C:\xampp\htdocs\test\index.php on line 15 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\index.php:1) in C:\xampp\htdocs\test\index.php on line 15 Any help would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/ Share on other sites More sharing options...
Miko Posted May 28, 2009 Share Posted May 28, 2009 You should put your session_start() at the very top of each page. Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844054 Share on other sites More sharing options...
Jibberish Posted May 28, 2009 Share Posted May 28, 2009 There cant be any output to the browser before you call session start, not even white space so like Miko said, put it at the very top of your page. Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844059 Share on other sites More sharing options...
PFMaBiSmAd Posted May 28, 2009 Share Posted May 28, 2009 That won't help when the output is started on line 1 of the file. You either have some characters before the <?php tag or your file has been saved in UTF-8 encoding and the BOM (Byte Order Mark) characters that the editor places at the start of the file are the output that is being sent to the browser. Make sure there are no characters in the file before the <?php tag and make sure your files is saved in ANSI (ASCII) encoding or if you must save the file in UTF-8 encoding, save it without the BOM. Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844061 Share on other sites More sharing options...
zamp0e Posted May 28, 2009 Author Share Posted May 28, 2009 Hello and thanks for the fast reply, although I have already tried to set session_start() on the top, like this: <?php session_start(); ?> <?php $host = "******"; $user = "******"; $pass = "******"; $db = "******"; And like this: <?php session_start(); $host = "******"; $user = "******"; $pass = "******"; $db = "******"; I'm still having the same warnings, although the line changes Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844062 Share on other sites More sharing options...
zamp0e Posted May 28, 2009 Author Share Posted May 28, 2009 Hello PFMaBiSmAd I'm sure the <?php tag is on top of the page and there is nothing over/infront of it. Althogh I'm not sure what you mean by saving the files in ANSI, where do I control that ? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844064 Share on other sites More sharing options...
cuiyang000 Posted May 28, 2009 Share Posted May 28, 2009 you have to put the session_start() to the first line, just follow the <?php then, if still doesn't work, create a new file and paste all the codes there, bcoz maybe here're space or something else infront of the <?php. and the reason is that maybe you create the file by some software. Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844065 Share on other sites More sharing options...
PFMaBiSmAd Posted May 28, 2009 Share Posted May 28, 2009 where do I control that ? It's part of your editor's file save/save as dialog. If the editor you are using does not have any settings related to the format the file is being saved as, you need to use a programming editor such as notepad++ http://notepad-plus.sourceforge.net/uk/site.htm Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844066 Share on other sites More sharing options...
zamp0e Posted May 28, 2009 Author Share Posted May 28, 2009 At last I found it, thanks alot for the help! Link to comment https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/#findComment-844133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.