Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

online

  • submit to reddit
        <?php
session_start();
include"db.php"; # Connect To the database
$active_sessions = 0;
$minutes = 5; # period considered active
if($sid = session_id()) # if there is an active session
{
    # DB connect here
    $ip = $_SERVER['REMOTE_ADDR']; # Get Users IP address
    # Delete users from the table if time is greater than $minutes
    mysql_query("DELETE FROM `active_sessions` WHERE 
    `date` < DATE_SUB(NOW(),INTERVAL $minutes MINUTE)")or die(mysql_error()); 
    <a href="http://www.twizap.com/game/tank-trouble-3.html">Tank Trouble 3</a>
    # Check to see if the current ip is in the table
    $sql = mysql_query("SELECT * FROM active_sessions WHERE ip='$ip'");
    $row = mysql_fetch_array($sql);
    # If the ip isn't in the table add it.
    if(!$row){
        mysql_query("INSERT INTO `active_sessions` (`ip`, `session`, `date`) 
        VALUES ('$ip', '$sid', NOW()) ON DUPLICATE KEY UPDATE `date` = NOW()")or die(mysql_error());
    }
    # Get all the session in the table
    $sessions = mysql_query('SELECT * FROM `active_sessions`')or die(mysql_error());
    # Add up all the rows returned
    $active_sessions = mysql_num_rows($sessions);
}
    # Print the final result
    echo'<b>Online Now: </b>'.$active_sessions;
?>    
        The online service <a href=http://www.dopa.go.th/online/inqelect.htm>here</a> aims to help people
check where they are to vote. However, it can be
used as ID certification as well.
# nnnn is the id to be checked
http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=nnnn
Here I make it into a function call.
import urllib, re
def getname(id):
  url = 'http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=' + str(id)
  src = urllib.urlopen(url).read()
  pat = '<H3> *(.*?) *<'
  name = re.findall(pat, src)[0]  # don't use other info
  return name

print getname(5100900050063)  # show a name (one of my relatives)