Jump to content

Archived

This topic is now archived and is closed to further replies.

SieRobin

Auto Logout

Recommended Posts

a CRON job is next to useless for this task.  as far as i know, there is no way to detect what sessions are currently active on the server, and as such, a CRON job serves no purpose.  you need to run something on each page, so you'll want to include the file.  a CRON is run by the server, not by a user, so it doesn't have access to the user's session information.

are you currently storing the user's information when they log in?  do you have a login system yet?  if not, then this is all a pretty pointless exercise.

Share this post


Link to post
Share on other sites
alrighty, well i included the file on each page, still didn't work, and of course i took your script and dubbed it into my own settings.. dunno what's up with it i guess.

Share this post


Link to post
Share on other sites
are you running log_action(), or are you just including the function definition file?

Share this post


Link to post
Share on other sites
i'm including a file with the log_action() in it called checkonline.php.

Share this post


Link to post
Share on other sites
you have to actually RUN the function.  put:

[code]log_action();[/code]

somewhere just below the function's definition.

Share this post


Link to post
Share on other sites
So I can include the file checkonline.php, but below the include i put, "log_action();"?

Share this post


Link to post
Share on other sites
You can use a seperate file for hadling sessions, for portability.  I have one se up that thats creates a session for each user.  The session will then last as long as you set it up for in php.ini.  Here one I borrowed from http://www.evoknow.com/downloads.php

Need to connect to the database first.

[code]
$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

        function sess_open($save_path, $session_name) {
          return true;
        }

        function sess_close() {
          return true;
        }

        function sess_read($key) {
                global $dbi, $DEBUG, $SESS_LIFE;

                $statement = "SELECT value FROM sessions WHERE " .
                      "sesskey = $key AND expiry > " . time();

                $result = $dbi->query($statement);

                if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                $row = $result->fetchRow();
                if ($row) {
                  return $row->value;
                }

                return false;
        }

        function sess_write($key, $val) {
                global $dbi, $SESS_LIFE;

                $expiry = time() + $SESS_LIFE;
                $value = addslashes($val);

                $statement = "INSERT INTO sessions VALUES ('$key', $expiry, '$value')";
                $result = $dbi->query($statement);

                if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>";

                if (! $result) {
                        $statement = "UPDATE sessions SET expiry = $expiry, value = '$value' " .
                              "WHERE sesskey = '$key' AND expiry > " . time();
                        $result = $dbi->query($statement);
                }

                return $result;
        }

        function sess_destroy($key) {
                global $dbi;

                $statement = "DELETE FROM sessions WHERE sesskey = '$key'";
                $result = $dbi->query($statement);
                if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>";

                return $result;
        }

        function sess_gc($maxlifetime) {
                global $dbi;

                $statement = "DELETE FROM sessions WHERE expiry < " . time();
                $qid = $dbi->query($statement);
                if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>";

                return 1;
        }

        session_set_save_handler(
                "sess_open",
                "sess_close",
                "sess_read",
                "sess_write",
                "sess_destroy",
                "sess_gc");
[/code]

You need to make some other files first to talk to it.
But shud give you all you need.

Share this post


Link to post
Share on other sites
[quote author=scottybwoy link=topic=101955.msg406530#msg406530 date=1154360871]
You can use a seperate file for hadling sessions, for portability.  I have one se up that thats creates a session for each user.  The session will then last as long as you set it up for in php.ini.  Here one I borrowed from http://www.evoknow.com/downloads.php

Need to connect to the database first.

[code]
$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

        function sess_open($save_path, $session_name) {
           return true;
        }

        function sess_close() {
           return true;
        }

        function sess_read($key) {
                global $dbi, $DEBUG, $SESS_LIFE;

                $statement = "SELECT value FROM sessions WHERE " .
                       "sesskey = $key AND expiry > " . time();

                $result = $dbi->query($statement);

                if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                $row = $result->fetchRow();
                if ($row) {
                   return $row->value;
                }

                return false;
        }

        function sess_write($key, $val) {
                global $dbi, $SESS_LIFE;

                $expiry = time() + $SESS_LIFE;
                $value = addslashes($val);

                $statement = "INSERT INTO sessions VALUES ('$key', $expiry, '$value')";
                $result = $dbi->query($statement);

                if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>";

                if (! $result) {
                        $statement = "UPDATE sessions SET expiry = $expiry, value = '$value' " .
                               "WHERE sesskey = '$key' AND expiry > " . time();
                        $result = $dbi->query($statement);
                }

                return $result;
        }

        function sess_destroy($key) {
                global $dbi;

                $statement = "DELETE FROM sessions WHERE sesskey = '$key'";
                $result = $dbi->query($statement);
                if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>";

                return $result;
        }

        function sess_gc($maxlifetime) {
                global $dbi;

                $statement = "DELETE FROM sessions WHERE expiry < " . time();
                $qid = $dbi->query($statement);
                if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>";

                return 1;
        }

        session_set_save_handler(
                "sess_open",
                "sess_close",
                "sess_read",
                "sess_write",
                "sess_destroy",
                "sess_gc");
[/code]

You need to make some other files first to talk to it.
But shud give you all you need.
[/quote]

Looks like a giant blur to me, lol.

Share this post


Link to post
Share on other sites

×

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.