Jump to content

Recommended Posts

Bear with me, I started session yesterday for the first time.

My sessions never expire. The php.ini on my host looks like the default php.ini with the session.gc_maxlife directive the default 1440. My code is as follows below, I put in bold what I found to be the parts that need looking at. What's wrong?
[font=Courier]
__________________________________________________
<?php
[b]session_start();[/b]

$msg="Login successful.";

[b]if($_SESSION['isLoggedIn'] = true) {
header("Location: http://script-dump.freehostia.com/alna/redirect.php?msg=$msg");
}[/b]

$dbServer = "mysql2.freehostia.com";
$dbUsername = "antmas10_rsp";
$dbPass = "thedog";

mysql_connect($dbServer, $dbUsername, $dbPass);
mysql_select_db($dbUsername) or die("Failed to grab database.");

if(isset($_POST['submit'])) {
$username=$_POST['username'];
$pass=md5($_POST['password']);
$result=mysql_query("SELECT username FROM login WHERE username='$username' AND password='$pass'");

[b] if (mysql_num_rows($result) == 1) {
  $_SESSION['isLoggedIn'] = true;
  header("Location: http://script-dump.freehostia.com/redirect.php?msg=$msg");
}[/b]
}
?>
__________________________________________________
[/font]
Link to comment
https://forums.phpfreaks.com/topic/35053-session-fails-to-expire/
Share on other sites

It could be related to your garbage collection.  If there are very few people visiting the site, and the garbage collection in the ini file is set to a very, very low percentage, it's going to be very unlikely that it emptys out the sessions at any logical time period.  If that is your problem at all.
http://script-dump.freehostia.com/phpinfo.php

It's default with session.gc_probability set to 1 and the session.gc_divisor set to 100. That means there is a 1% chance?

[quote]if($_SESSION['isLoggedIn'] = true) {

= is setting it to true. use == to compare.[/quote]
Thanks for pointing that out, I always make that mistake.
I saw it last night but kind of skipped over it.

From PHP.net:
[quote]session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor...[/quote]

http://www.php.net/manual/en/ref.session.php#ini.session.gc-divisor
Free server. I am not sure if they allow me to have my own php.ini. Now, could I use ini_set() to edit the gc  probability directive? I know ini_set only works during script execution, but it makes sense in my mind that it would work and I would only need the gc probability directive to be changed during execution.
No, unfortunately it wouldn't. The reason it, something like that affects the actual php engine itself, the entire way sessions are handled, I am 90% sure that won't have any affect on it at all, however, since you can't kill the session early, destroy the session manually.    Go into where the session "file's" are on the server, and once per week, clear them all out? NEver encountered that type of problem before.
Good night, and thanks a lot so far.

I went ahead and tried the ini_set() and set the probability to 100 (100%). My long overdue session was gone when I visited the admin login. Maybe it did work? I'll check back in 24 minutes when my session should be expired again.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.