Howdy all! Can someone enlighten me about handling sessions with session_start and the other session functions? I have used session_start on all the pages I need session control for, and I have set the session variable in my login code. Likewise, I check the variable using session_is_registered("variable") to produce output if returned true. My problem is this...if a user quits out of their browser without logging-out via my site's logout page, which uses session_unregister("variable") and session_destroy, they are unable to use the site successfully upon next login without first going through the logout page. They can log in, but when any other page is attempted the session isn't read by the page and they are required to login.
Additionally, and this is a sidenote to my main problem above, is there a quick method to controlling the session when the user exits the page at all (i.e. the BACK button)? I'm getting better with PHP, however I've read all the session stuff at PHP.net and still haven't been able to resolve the problem. Thanks!
session_start help
Moderator: General Moderators
I hope this helps
I dont know if this will help, but here is how I use sessin varibles:
Code: Select all
<?php
session_start();
mysql_connect("localhost:3306", "troop21") && mysql_select_db("troop21")
or $failed = "Could not connect to database.";
$loginform = " User: <input type="text" size="13" name="pn" maxlength="16" />
Pass: <input type="password" size="13" name="pw" maxlength="12" />
<input type="submit" value="Login" />";
$result = mysql_query("select * from users where patrolnum="$pn"");
$row = mysql_fetch_assoc($result);
if($rowї"password"]==md5($pw) && !session_is_registered("loggedin"))
{
$loggedin=$pn;
session_register("loggedin");
}
else if(session_is_registered("loggedin"))
{
$logerror="<img src="smile.gif" height="13" width="13" /> <b class="MESSAGE">You're already logged in.</b>";
}
else if($rowї"password"]!=md5($pw))
{
$pwerror="<b class="RED">ERROR:</b> <b class="MESSAGE">Username or password did not match!</b>";
} ?>