chocopi Posted May 20, 2007 Share Posted May 20, 2007 Firstly, once you have started and registered the sesssion when you change page does the session continue or do you have to call it? Secondly, how can you check if the session has been started and if its false then they are redirected to the login (to stop users from going to pages without logging in) Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/ Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 You don't register sessions, if your talking about session_register() it has long been depricated. Sessions are passed from page to page but each page needs a call to session_start(). To check a session variable has been set, use something like.... <?php session_start(); if (!isset($_SESSION['logged'])) { // user is NOT logged in. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257742 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 okay thanks, but in your code where did the 'logged' be come from ? Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257744 Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 You set that when you actually log the user in. Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257748 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 so you would have a variable set as <?php $session = 'logged'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257751 Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 so you would have a variable set as No... more like... <?php // code to varify valid user goes here. session_start(); $_SESSION['logged'] = true; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257754 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 Thanks for your help ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257758 Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 ok thanks, just out of intrest could you replace the 'logged' past with user id which is taken from the database Yeah... you can replace it with whatever you think you'll need to follow a user around with. for a login system, I usually use a few variables. Something like... $_SESSION['logged'] = true; $_SESSION['uname'] = $row['uname'] $_SESSION['perms'] = $row['perms'] Where $row is the users record pulled from the database upon login varification. Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257763 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 thanks, but i didnt mean to post that i was looking in the wrong file as i already had it working. Many Thanks thorpe ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/#findComment-257767 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.