Thanks for the reply and here the code from the state.php:
<?php
/*
* Copyright (c) 2008 AlstraSoft -- http://www.alstrasoft.com
* Author: AlstraSoft
*
* This script is the property of the author and may not be distributed in any way
* without explicit permission from the author.
*
*
*/
?><?php
function InitializeState()
{
$query = "SELECT `key` FROM tbl_state";
$result = mysql_query($query);
if (mysql_num_rows($result)==0)
{
$query = "INSERT INTO tbl_state (`key`,`timestamp`,`waiting`) VALUES('','0','0')";
if (!mysql_query($query)) echo "ERROR: ".mysql_error()."<BR>";
}
}
function GetStateVars()
{
InitializeState();
$query = "SELECT * FROM tbl_state";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
return $row;
}
function GenerateNewKey()
{
$ret = "";
for($i=1;$i<=15;$i++) $ret=$ret.GenerateNewChar();
return $ret;
}
function ClearKey()
{
InitializeState();
$query = "UPDATE tbl_state SET `key` = ''";
if (!mysql_query($query)) echo "ERROR: ".mysql_error()."<BR>";
}
function GetThreadKey()
{
$statevars = GetStateVars();
return $statevars["key"];
}
function RegisterTimeStamp($key,$waiting = -1)
{
InitializeState();
if ($waiting==-1)
{
$query = "UPDATE tbl_state SET `key` = '".$key."', `timestamp` = '".time()."'";
}
else
{
$query = "UPDATE tbl_state SET `key` = '".$key."', `timestamp` = '".time()."', `waiting` = '".$waiting."'";
}
if (!mysql_query($query)) echo "ERROR: ".mysql_error()."<BR>";
}
function GetWaiting()
{
$statevars = GetStateVars();
return $statevars["waiting"];
}
function SetWaiting($waiting)
{
InitializeState();
$query = "UPDATE tbl_state SET `waiting` = '".$waiting."'";
if (!mysql_query($query)) echo "ERROR: ".mysql_error()."<BR>";
}
function RegisterThread()
{
$ret = GenerateNewKey();
RegisterTimeStamp($ret,0);
return $ret;
}
function ValidateThread($pop3 = null)
{
global $threadkey;
global $threadspacer;
if ($threadkey=="") return;
if (time()==$threadspacer) return;
$threadspacer = time();
$statevars = GetStateVars();
if ($threadkey!=$statevars["key"])
{
if ($pop3!=null) $pop3->Close();
require("closedb.php");
exit;
}
else
{
RegisterTimeStamp($threadkey);
}
}
function NeedToLaunchThread()
{
$statevars = GetStateVars();
if (($statevars["key"]=="")) return true;
if ((time()-$statevars["timestamp"])>30) return true;
SetWaiting(1);
return false;
}
?>