Forums / Developer / Basic querystring/session variable question

Basic querystring/session variable question

Author Message

Graham Tillotson

Thursday 21 August 2003 6:39:23 pm

I need to setup a link into my ezPublish site that traps querystring values and stores them as session variables. Here is the code that I have working on index.php:

// Get querystring values
$userstate=$HTTP_GET_VARS["state"];
$userguid=$HTTP_GET_VARS["uguid"];

// Store as session variables
$http->setSessionVariable( "userstate", $userstate );
$http->setSessionVariable( "userguid", $userguid );

// Transfer to locals
$puserguid = $http->sessionVariable( "userguid" );
$puserstate = $http->sessionVariable( "userstate" );

echo "Querystring Data:<br>";
echo ("State value " . $puserstate . "<br>");
echo ("UGUID value " . $puserguid . "<br><br>");

My question is this -- how do I setup the link and where do I put the code? In ASP I would put it in the Session_OnStart event. I see that ezPublish has the eZSessionStart function in ezsession.php, but I'm not sure how to use it.

Thanks,
GRT

DUO : CONSULTING
Web content management experts
www.duoconsulting.com

Graham Tillotson

Friday 22 August 2003 3:04:53 pm

An update to my own question here. Not sure if this is the best way, but it works. I have added the code below to index.php. I check for a new session, and on the first link into the application I look for querystring values. If found, I store them as session variables and in a custom table I created (not sure which ones I want to use yet).

$mysessionstarted = $http->sessionVariable( "mysessionstarted" );

if (!$mysessionstarted ) {

// Look for User GUID
if ( $http->hasGetVariable( "uguid" ) )
{ $userguid = $HTTP_GET_VARS["uguid"]; }
else { $userguid= "0"; }

// Look for U.S. State
if ( $http->hasGetVariable( "state" ) )
{ $userstate = $HTTP_GET_VARS["state"]; }
else { $userstate = "UNKNOWN"; }

// Look for Department
if ( $http->hasGetVariable( "department" ) )
{ $userdepartment = $HTTP_GET_VARS["department"]; }
else { $userdepartment = "UNKNOWN"; }

// Set session variables
$http->setSessionVariable( "userguid", $userguid );
$http->setSessionVariable( "userstate", $userstate );
$http->setSessionVariable( "userdepartment", $userdepartment );

// Set other values needed to log the vist
$sessionid = $http->sessionID();
$accessdate = date("Y-m-d H:i:s");

// Set flag that the session has started
$http->setSessionVariable( "mysessionstarted ", true );

// Run update to log the user session. Note that this is a bit redundant in that
// EZ logs the session in ezsession. The complexity with the default is that ALL
// session variables in ezsession are stored in a delimited string (the data field).
// These values are harder to examine and extract than in our dedicated table.
// Plus, the ezsession table is a working table, so it gets flushed.

// Start a new transaction
$db->begin();

// Send SQL
$db->query("INSERT INTO ezloginhistory ( session_id, uguid, state, department, access_date ) VALUES ( '$sessionid', '$userguid', '$userstate', '$userdepartment', '$accessdate' )" );

// Commit the transaction
$db->commit();

/*
// test out fetching data back by SessionID
$rows =& $db->arrayQuery( "SELECT * FROM ezloginhistory WHERE session_id = '$sessionid'" );
foreach ( $rows as $row )
{ print( $row["state"] ); }
*/

}

DUO : CONSULTING
Web content management experts
www.duoconsulting.com