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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 06:04:07
Script start
Timing: Jan 31 2025 06:04:07
Module start 'layout'
Timing: Jan 31 2025 06:04:07
Module start 'content'
Timing: Jan 31 2025 06:04:08
Module end 'content'
Timing: Jan 31 2025 06:04:08
Script end

Main resources:

Total runtime1.0289 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.2656151.2266
Module start 'layout' 0.00620.0031 739.492236.6797
Module start 'content' 0.00931.0188 776.1719914.1797
Module end 'content' 1.02820.0007 1,690.351611.8125
Script end 1.0289  1,702.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3158160.0002
Check MTime0.00120.1206160.0001
Mysql Total
Database connection0.00100.101510.0010
Mysqli_queries0.970794.3391520.0187
Looping result0.00040.0374500.0000
Template Total0.981295.420.4906
Template load0.00220.211220.0011
Template processing0.979095.149820.4895
Template load and register function0.00120.118810.0012
states
state_id_array0.00150.145910.0015
state_identifier_array0.00160.157220.0008
Override
Cache load0.00200.1898660.0000
Sytem overhead
Fetch class attribute can translate value0.00050.046310.0005
Fetch class attribute name0.00180.177030.0006
XML
Image XML parsing0.00220.209910.0022
class_abstraction
Instantiating content class attribute0.00000.001040.0000
General
dbfile0.00300.2959160.0002
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
15content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs