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

eZ debug

Timing: Jan 18 2025 18:26:23
Script start
Timing: Jan 18 2025 18:26:23
Module start 'content'
Timing: Jan 18 2025 18:26:24
Module end 'content'
Timing: Jan 18 2025 18:26:24
Script end

Main resources:

Total runtime0.9620 sec
Peak memory usage4,096.0000 KB
Database Queries189

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 587.8438180.8125
Module start 'content' 0.00840.8311 768.6563523.5156
Module end 'content' 0.83950.1225 1,292.1719337.0547
Script end 0.9619  1,629.2266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3980210.0002
Check MTime0.00150.1535210.0001
Mysql Total
Database connection0.00160.164510.0016
Mysqli_queries0.884691.95221890.0047
Looping result0.00170.18171870.0000
Template Total0.930096.720.4650
Template load0.00200.208020.0010
Template processing0.928096.463420.4640
Template load and register function0.00010.012710.0001
states
state_id_array0.00120.127310.0012
state_identifier_array0.00100.105720.0005
Override
Cache load0.00180.1823660.0000
Sytem overhead
Fetch class attribute can translate value0.00160.167520.0008
Fetch class attribute name0.00110.116530.0004
XML
Image XML parsing0.00070.070420.0003
class_abstraction
Instantiating content class attribute0.00000.000940.0000
General
dbfile0.00180.1823270.0001
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs