ady_bavarezu89 Posted May 30, 2013 Author Share Posted May 30, 2013 That is NOT what session_start() it is not? why is user_id null (Notice: Undefined index: user_id in) when I go to b.php the second time then? The first time it shows 1 as it should but from the second time it becomes undefined. Link to comment https://forums.phpfreaks.com/topic/278442-variables-initialize-everytime-i-go-to-a-page/page/2/#findComment-1433228 Share on other sites More sharing options...
ady_bavarezu89 Posted May 30, 2013 Author Share Posted May 30, 2013 it is not? why is user_id null (Notice: Undefined index: user_id in) when I go to b.php the second time then? The first time it shows 1 as it should but from the second time it becomes undefined. I think I found my problem....On my page b.php I also had a logout option. Which means that if I press a button my session is destroyed. and I did it that way: <button class="btn btn-primary" type="submit" onclick="myFunction()"> </button> <script> function myFunction(){ <?php session_destroy(); ?> } </script> So php is interpreting my php code even if it's inside a javascript function that wasn't called. That's why that guy warned me about using javascript and php! Link to comment https://forums.phpfreaks.com/topic/278442-variables-initialize-everytime-i-go-to-a-page/page/2/#findComment-1433234 Share on other sites More sharing options...
ady_bavarezu89 Posted May 30, 2013 Author Share Posted May 30, 2013 This time it finally works. It stores my session and more users can be logged in at the same time. Finally!! Link to comment https://forums.phpfreaks.com/topic/278442-variables-initialize-everytime-i-go-to-a-page/page/2/#findComment-1433242 Share on other sites More sharing options...
Jessica Posted May 30, 2013 Share Posted May 30, 2013 PHP and Javascript are executed at completely different points in the process. Link to comment https://forums.phpfreaks.com/topic/278442-variables-initialize-everytime-i-go-to-a-page/page/2/#findComment-1433259 Share on other sites More sharing options...
ady_bavarezu89 Posted May 30, 2013 Author Share Posted May 30, 2013 PHP and Javascript are executed at completely different points in the process. Got it! I didn't knew that. Thanks a lot for the suggestions and everything Link to comment https://forums.phpfreaks.com/topic/278442-variables-initialize-everytime-i-go-to-a-page/page/2/#findComment-1433280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.