circle.ch weblog by Urs Gehrig

 Search
A weblog about libre software, law, technology, politics and the like.
2013-05-11T15:38:07
Academic, Android, Apache, Apple, Art, Best Of, Biotech, Civil Society, Content Management, Cooking, Copyright, Creative Commons, Crosspost, Culture, Database, Deutsch, DRM, Economy, Education, Event, Gadget, General, Geodata, Government, Health, Howto, Humor, Innovation, Intellectual Property, Java, Language, LaTeX, Law, Linux, Media, Moblog, Mozilla, Music, Office, Open Content, Open Source, P2P, PHP, Podcast, Politics, Privacy, Projects, Random Thought, Rant, Science, Search, Social Network, Software, Sport, Talks, Technology, Technology Transfer, Travelling, Weblog, Wiki, Wireless and Mobile, XML

27. March 2001

Removing obsolete session from the DB
@ 20:58:50

Abstract

Somewhere you may have a table with active_session of visitors using your site. From time to time you would like to remove obsolete session. The script below is using mktime() to fit the timestamp stored in the DB. I use to remove session in this example that are older than two days.

Script

<?php
/**
* Author: Urs Gehrig <urs_at_circle_ch>
* Date: 27-3-2001
*
* Subject: how you could remove your sessions older
* than _x_ days from your database.
*/
require_once("prepend.php");
page_open(array( "sess" => "ac_session",
"auth" => "ac_default_auth",
"perm" => "ac_perm",
"user" => "ac_user" ));
?>
<?php
/**
* delete sessions from database older than 2 days
* delete ac_user and ac_session
*/
$db = &new db_yourdb();
$cfg->active_sessions = "ac_active_sessions";

/**
* building the reference date
* $expired contains something like "20010327231519"
*/
$expired = strftime("%Y%m%d%H%M%S",
mktime(
date("H"),
date("i"),
date("s"),
date("m"),
date("d")-2,
date("Y")
) );
/**
* building the sql query
*/
$sql = "DELETE FROM
$cfg->active_sessions
WHERE
changed < '$expired'
AND
name
LIKE
'%ac_%'";

/**
* executing the query
*/
$db->query($sql);

?>
<?php
page_close();
?>

to be cont'd

Links

http://phplib.netuse.de - PHPLIB home
http://ch.php.net/mktime - PHP function reference

Comments (0) Permalink del.icio.us

The URL to TrackBack this entry is:
   http://circle.ch/blog/b2trackback.php/567

Comments closed.



Werbung:

Beiträge von Dritten:

Nachfolgende Titel verweisen auf von mir gelesene Weblogs.

Feeds:

Blog Content
Blog Comments

WikiAgenda:

Comments:

Good question, but...
Hi, thank you very...
Unter http://www.s...
Ich weiss mir nich...
ThanQ matthias. Th...
in case you just w...
ich liebe dir, urs...
hi there, sorry i...
Hoi Leo. I haven'...
Do you know the si...

Archives:

Blog stack:

Bill Humphries
monorom
Wendy M. Seltzer
Christian Stocker
Roger Fischer
Sandro Zic
Wez Furlong
Ben Hammersley
George Schlossnagle
Joichi Ito
Lawrence Lessig
Derek Slater
Karl-Friedrich Lenz
John Palfrey
Bernhard A.M. Seefeld
Gregor J. Rothfuss
Rainer Langenhan
Elke Engel
Sebastian Bergmann
Simon Willison
Jeremy Zwaodny
Udo Vetter
Axel A. Horns
Miguel de Icaza
Andreas Halter
Silvan Zurbrügg
Hannes Gassert
Markus Koller


$Date: 2005/11/05 11:14:30 $