What I an trying to achiev is a script that is included in every page. It will check the existance and validate a unique id 32 chars.
If the id is invalid,expired or none existant it shoud reload the main index2.php
this what I have so far .
I have had to use getttype incase some one type is xid= or xid becaus isset return true in those cases.
And if there is a fatal error i.e no mysql connection diverts to an errror page
My aim is no cookies and no client side script and no browser or server specific stuff. Also to keep the code php3 and 4 compat.
Here is what I have so far --
<?php
Include ("../libs/dbase.php"); // generic dbase connection.
Include ("../libs/session.php");
$SERVER_NAME = getenv("SERVER_NAME");
$dba = new session;
$xiderror = 0;
$fredtype = gettype($xid); // use this because isset return true for ?xid= and ?xid
$fredlength = strlen($xid);
if($fredtype == "NULL" || $fredlength <> 32)
{
$xid = 0;
$xiderror = 1;
}
If (!$xid == 0) // could and the stuff here
{
if (!ereg("[0-9a-z]{32}$",$xid))
{
$xiderror = 1;
$xid =0;
}
else
{
if (!$session_ok = $dba->make_session($xid))
{
$xid=0;
$xiderror = 1;
}
}
}
If ($xiderror)
{
$dba->seshid=0;
if ($session_ok = $dba->make_session(0))
{
$session_id = $dba->seshid;
$xid = $session_id;
$destination = sprintf("http://%s/index2.php?xid=%s",$SERVER_NAME,$session_id);
//unset($dba);
Header("location: $destination");
exit;
}
Else
{
$destination = sprintf("http://%s/sorry.html",$SERVER_NAME);
Header("location: $destination");
exit;
}
}
else
$xid = $dba->seshid;
?>