Waliser Posted March 12, 2012 Share Posted March 12, 2012 Hello all, I have tried to fix this many a time before but never managed it. However now it is really annoying me as it clogs up my error file. <?php session_start(); session_register('sid'); if (isset($_SESSION['sid'])) { } else { $tmp = md5(microtime()); $_SESSION['sid']=$tmp; } $db_server = "server"; $db_name = "name"; $db_user = "user"; $db_passwort = "pw"; $db = @MYSQL_CONNECT($db_server,$db_user,$db_passwort) or die ("no connection please contact me"); $db_check = @MYSQL_SELECT_DB($db_name); ?> This little file is called from every page on my website and is causing this line to appear lots [11/Mar/2012:21:00:18 +0100] PHP Notice: A session had already been started - ignoring session_start() in /home/www/EN/config/config.php on line 2 What is the correct way of setting the session i.e. how do I correctly start it at a given point and then keep it throughout? From my understandin in the older php versions I could have just used session_register('sid'); and didn't need the start (but if I did that then had error) while now I have just read that the session_register('sid') has been removed as of 5.4.0. Help would be muchly appreciated, I don't use php that often, just made my site work in the beginning and ignored this but it annoyed me the other day when I saw the size of the error file. thank you Waliser Quote Link to comment https://forums.phpfreaks.com/topic/258769-how-to-startkeep-sessions-correctly/ Share on other sites More sharing options...
timmah1 Posted March 12, 2012 Share Posted March 12, 2012 Have you read this http://www.phpfreaks.com/forums/index.php?topic=37442.0 Quote Link to comment https://forums.phpfreaks.com/topic/258769-how-to-startkeep-sessions-correctly/#findComment-1326557 Share on other sites More sharing options...
Waliser Posted March 13, 2012 Author Share Posted March 13, 2012 I did, but it might be that I am reading it wrongly. My standard pages start <? include("config.php"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> The config is what I wrote in the prev post. I don't see that I am outputting anything prior to the session. I am most likely a bit slow here sorry. thanks Quote Link to comment https://forums.phpfreaks.com/topic/258769-how-to-startkeep-sessions-correctly/#findComment-1327006 Share on other sites More sharing options...
DavidAM Posted March 13, 2012 Share Posted March 13, 2012 ... A session had already been started ... It is possible that you are including a php file that is itself including config.php. If this is the case, you can either change config.php to not start a session if one has already been started, or change all of the include('config.php'); statements in all of your files to be include_once('config.php'); It is also possible that your php.ini is setup to automatically start a session for all requests. In this case, you can either disable this setting in the ini file, or (again) change the config.php to not start a session if one has already been started. Quote Link to comment https://forums.phpfreaks.com/topic/258769-how-to-startkeep-sessions-correctly/#findComment-1327011 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.