suckerpunch Posted March 23, 2013 Share Posted March 23, 2013 Do I have to write session_start() before I define a new session variable? Quote Link to comment https://forums.phpfreaks.com/topic/276065-can-i-define-a-session-variable-before-session_start/ Share on other sites More sharing options...
Love2c0de Posted March 23, 2013 Share Posted March 23, 2013 (edited) Yes. It must be at the very top of your code also. <?php session_start(); //now you can set session variables anywhere in the script. ?> Kind regards, L2c. Edited March 23, 2013 by Love2c0de Quote Link to comment https://forums.phpfreaks.com/topic/276065-can-i-define-a-session-variable-before-session_start/#findComment-1420575 Share on other sites More sharing options...
davidannis Posted March 23, 2013 Share Posted March 23, 2013 I believe that you can put the session_start below the first line AS LONG AS you have no output to the browser before the session_start. If you have output to the browser then the header has already been sent and you get an error to that effect so it is usually good practice to put it right at the top. Quote Link to comment https://forums.phpfreaks.com/topic/276065-can-i-define-a-session-variable-before-session_start/#findComment-1420592 Share on other sites More sharing options...
suckerpunch Posted March 23, 2013 Author Share Posted March 23, 2013 Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/276065-can-i-define-a-session-variable-before-session_start/#findComment-1420608 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.