The whole idea of a session exactly that, that it ends when the browser is closed.
You'll need to store the Session ID in a cookie and resume it later if you want to maintain it on a browser close and reopen.
The whole idea of a session exactly that, that it ends when the browser is closed.
You'll need to store the Session ID in a cookie and resume it later if you want to maintain it on a browser close and reopen.
I have confirmed that by placing the session_set_cookie_params before the session_start that all works well. This code functions properly, and maintains a session even after the browser is closed and reopened:
<?
session_set_cookie_params(3600);
session_start();
if(!isset($_SESSION['test'])) {
$_SESSION['test'] = "session is still set";
echo "setting variable";
} else {
echo $_SESSION['test'];
}
?>
hey matt this is the code i got and it dosnt seem to work,
<?
session_set_cookie_params(3600);
session_start();
session_register("username");
session_register("password");
mysql_connect("$sql_host", "$sql_user", "$sql_pass") or DIE("Couldnt Connect to SQL Host");
mysql_select_db("$sql_db") or DIE("Couldnt select database");
$sql = mysql_query("SELECT password FROM users WHERE username='$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $password == $fetch_em["password"]){
$time = time();
$valid_user=1;
$software=GETEnv("HTTP_USER_AGENT");
mysql_query("UPDATE users SET software='$software' WHERE username='$username'");
mysql_query("UPDATE users SET addr='$REMOTE_ADDR' WHERE username='$username'");
$query="SELECT username FROM online WHERE username='$username'";
$result=mysql_query($query) or die("Query failed");
$there=mysql_num_rows($result);
if($there=="0"){
mysql_query("INSERT INTO online VALUES ('$time','$username')");
}
mysql_close();
}
else {
$valid_user=0;
}
?>
Where is $username getting set to start with?
You should call session_register() after you place a value in the variable you want to register, not before hand. You only need to call session_register to place the variable into the session. Not each time you want to access the variable.
that script gets executed by the form (login form)
ryza
This question concers this subject so that's why I post it in here.
I have an login system with sessions
Everything works fine, session get destroyed when I press logout...
For that, np
only, when I just close the browser, like members dare to do, instead of using the logout button
normally a session should be destroyed
but in my case, it keeps it on my server...
do I need to change some settings or what?
pleaze help me, we are with 2 and we've been searching for a whole day now so... (I mean yesterdau )
thx in advance
greetz
system
The garbage collector should be run any time a session is started, so as long as another user visits your page, the garbage collector will clean up the old ones.
They're not destroyed unless you log out, but they do expire.
with another user, you mean a new browserwindow or a new IP address, on what is the sessionID based on?
because if I try a new window, after closing it, than it doens't get deleted
and they expire you say, I think it's in the php.ini, but I don't know which field, which is it?
and how much time until it expires
and does it mean the session is deleted, gone from the server or empty or ...
pleaze enlighten me with your wisdom
thx in advance, I really appreciate it
greetz
system
when u call session_start, php scans for expired sessions on the server, and deletes them. that is to say, the next time someone visits your site, any old sessions will be culled.
session_destroy has the same effect, immediately deleting the current session on the server.
the maximum duration of a session is set in php.ini, IIRC, and by default, the cookie is set to expire when the browser is closed.
Originally posted by daveyboy
session_destroy has the same effect, immediately deleting the current session on the server.
the maximum duration of a session is set in php.ini, IIRC, and by default, the cookie is set to expire when the browser is closed.
sowwy, I've let it rest for some time, been busy with some other parts...
it still doens't work...
session.cookie_lifetime=0
session.gc_maxlifetime=50
session.cache_expire=1
but still the session doen't get detroyed when I (the user) close the browser...
anybody?
I'v searched through 10-20-30 pages but nothing seems to help me give an answer so...
The best you could do is set up a cronjob to delete the files (or visit the page, which will run the garbage collector).
Originally posted by Mordecai
The best you could do is set up a cronjob to delete the files (or visit the page, which will run the garbage collector).
there is no other way
I mean: a php way...
not something dune by linux...