lilwing Posted June 18, 2008 Share Posted June 18, 2008 Every time I try to make a session, it is usually only active until you visit another page. I would like to know how to force the session to be active until logoff/period of inactivity. Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2008 Share Posted June 18, 2008 It is likely that the session is not really starting on the first page or you are not starting it on the next page. In any case, post your code to get specific help with what it is or is not doing. Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568371 Share on other sites More sharing options...
.josh Posted June 18, 2008 Share Posted June 18, 2008 by "visit another page" do you mean some other external page, or something internal on your own site? If it's the first, you can set a cookie and check for it on page loads. If it's the second...do you have session_start() at the top of the page in question? Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568373 Share on other sites More sharing options...
lilwing Posted June 18, 2008 Author Share Posted June 18, 2008 Do you have to include session_start on every page? this is the php on the first page: <?php session_start(); $_SESSION['logged'] = false; $_SESSION['uid'] = 0; $_SESSION['username'] = ''; ?> Then there is a verification page, which redirects to the second page: <?php ob_start(); //Login info $host=""; $sqlusername=""; $sqlpassword=""; // Connect to server mysql_connect("$host", "$sqlusername", "$sqlpassword")or die("Unable to connect"); //SQL info $db_name=""; $tbl_name=""; //Select database mysql_select_db("$db_name")or die("Unable to select database"); //Assign post data from the login page to a variable $username=$_POST['username']; $password=$_POST['password']; $passwordencrypted = md5($password); //Variable containing SQL instruction $verification="SELECT * FROM $tbl_name WHERE username='$username' and password='$passwordencrypted'"; //Variable containing Query of SQL instruction $result=mysql_query($verification); //Variable containing # of query matches $count=mysql_num_rows($result); //If username and password are correct... if($count==1) { //Register username, password and redirect to page desired _setSession(); header("location:basicadminpage.php"); //insert location } else { //If username and password are incorrect... echo "Access denied"; } //End output buffer mysql_close(); ob_end_flush(); ?> and the 2nd page <?php if (defined('SID')) { echo 'Session is active'; } else { echo 'Session is not started'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568376 Share on other sites More sharing options...
.josh Posted June 18, 2008 Share Posted June 18, 2008 yes, you have to have session_start() before accessing any session vars etc.. on every page you wish to have access to them. Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568378 Share on other sites More sharing options...
lilwing Posted June 18, 2008 Author Share Posted June 18, 2008 Okay, I have session_start on each page. Here is how I am testing it: <?php session_start(); $_SESSION['logged'] = false; $_SESSION['uid'] = 0; $_SESSION['username'] = ''; ?> <?php session_start(); if ($_SESSION['uid']=0) { echo "fuck fuck fuck!";} if (defined('SID')) { echo 'Session is active'; } else { echo 'Session is not started'; } ?> If the test worked, it should have echoed "fuck fuck fuck!" But I am not sure what I did wrong. Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568387 Share on other sites More sharing options...
Dragoa Posted June 18, 2008 Share Posted June 18, 2008 Quick Glance[Not to sure on PHP syntax]: $_SESSION['uid']=0 Should be: $_SESSION['uid']==0 Looks like you dropped an = sign in your check. Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568396 Share on other sites More sharing options...
lilwing Posted June 18, 2008 Author Share Posted June 18, 2008 Victory. Quote Link to comment https://forums.phpfreaks.com/topic/110781-solved-how-to-force-sessions-to-be-active-until-logoff-or-a-period-of-inactivity/#findComment-568401 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.