Amit20 Posted July 2, 2011 Share Posted July 2, 2011 Hi friends, i m in learning stages of php. I m creating a login/logout page. Is it necessary to add session_start() in every page of php??? As i created one page to start a session for user. But when i try to echo $_SESSION variable in another page it gives me a Notice as follows; Notice: Undefined variable: _SESSION in D:\public_hmtl\mysite\php\sms\form.php on line 87. again when i mentioned session_start() at the page where i m redirecting the user it show the value???? Quote Link to comment https://forums.phpfreaks.com/topic/240926-session_start/ Share on other sites More sharing options...
requinix Posted July 2, 2011 Share Posted July 2, 2011 session_start() needs to be executed for every script PHP runs. The easiest way to do that is to put a call to it in all your files. Meanwhile, the most common method way is to put that in just one file and include() it in all the other files. You can then put other "common" actions in there, like checking if a user is logged in or connecting to a database. Quote Link to comment https://forums.phpfreaks.com/topic/240926-session_start/#findComment-1237561 Share on other sites More sharing options...
Amit20 Posted July 2, 2011 Author Share Posted July 2, 2011 Thank you requinix Quote Link to comment https://forums.phpfreaks.com/topic/240926-session_start/#findComment-1237563 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.