Forum Moderators: coopster

Message Too Old, No Replies

session start() issue

         

username

9:51 pm on Apr 20, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi all, I am having a very strange issue with initialzing a session variable. Basically I am just trying to setup a username session. My code is this:

function setUpSession($username){
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['username'] = $username;
}
}

The above code is included via another file, but including it in the page makes no difference, I still get the below errors.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /usr/home/site/www/htdocs/join/index.php:33) in /usr/home/site/www/htdocs/classes/clsSession.php on line 50

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /usr/home/site/www/htdocs/join/index.php:33) in /usr/home/site/www/htdocs/classes/clsSession.php on line 50

clsSession is where the session_start function is. Line 33 in the index.php file is where the </head> tag closes. From all my reading everyone says it is a white space issue after a php tag somewhere. I even checked my php configuration file, and that seemed ok to. I am lost as to what this issue is, if it is not a whitespace issue, then what is it? Can someone please help.

Thanks in advance.

IanKelley

12:21 am on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try either using output buffering or calling your session function before anything whatsoever is sent to the browser.

username

5:18 pm on Apr 21, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks a lot. That worked perfectly. Remember, for anyone who does run into this issue, to run the command before the document declarations etc with a conditional statement which checks whether the session variable has been created already, otherwise you will end up with a whole heap of useless session variables hanging around.