Session variables missing when redirecting from extension

Author Message

Luis Cruz

Thursday 12 October 2006 2:28:26 pm

Here is the situation; I have an extension that uses the PEAR::HTML_Quickform package. When the form submits, it submits to itself and calls functions to perform input validation and process the data. In my data processing function, I attempt to set some session variables and depending on what happens redirect to another extension.

However, when I arrive at the second extension, the session variables I have set have disappeared. I've checked the session ID, and it does not change between the form and the extension you get redirected to. Prior to the redirect, a dump of the $_SESSION variable shows that the information is set. But, you get to the next page and the $_SESSION variable dump shows the information is gone.

I have tried a number of methods to set the variables and redirect to the page. A skeleton of my extension is below; I'll add in the various methods I have tried. No clue as to why this is happening. Using eZ 3.6.3, PHP 4.3.9.

<?php
/**
 * Include eZ publish libraries and set necessary module variables 
 */
include_once("kernel/common/template.php");
include_once( "lib/ezutils/classes/ezuri.php" );
include_once( "lib/ezutils/classes/ezhttptool.php" );

$eZURI =& eZURI::instance();
$userParameters = $eZURI->userParameters();

$http =& eZHTTPTool::instance();

$Module =& $Params["Module"];
$Module->setTitle("View");

/**
 * Include libraries and set necessary variables
 */
$directoryLevel = "/path/to/classes/";
require_once($directoryLevel . "class/Foo.php");

/**
 * Form processing functions
 */
function doSomething($formData)
{
    // Method 1:  failure
    $_SESSION["stuff"] =& $stuff;
    header("Location:  /path/to/somewhere\r\n");
    exit();

    // Method 2:  failure
    $http =& eZHTTPTool::instance();
    $http->setSessionVariable("stuff", $stuff);
    $http->redirect("/path/to/somewhere");

    // Method 3:  failure
    $http =& eZHTTPTool::instance();
    $http->setSessionVariable("stuff", $stuff);
    header("Location:  /license/upgrade\r\n");
    exit();

    // Method 4:  failure
    $_SESSION["stuff"] =& $stuff;
    eZSessionStop();
    header("Location:  /path/to/somewhere\r\n");
    exit();

    // Method 5:  failure
    $http =& eZHTTPTool::instance();
    $http->setSessionVariable("stuff", $stuff);
    eZSessionStop();
    $http->redirect("/path/to/somewhere");

    // What will bring success?!
}

/**
 * Build the form
 */
$defaultInfo = array(
    );

// Create the form
$form =& new HTML_QuickForm("form", "post", $_SERVER["REQUEST_URI"], "_self", "", true);

$result = "";
// If the form validates, process the data.
if ($form>validate()) {
    $result = $form->process("doSomething", false);
}

// Create the eZ publish template
$tpl =& templateInit();
$tpl->setVariable("module", $Module );
$tpl->setVariable("text", $text);

// Set the eZ publish template variables
$Result = array();
$Result["content"] =& $tpl->fetch("design:license/ezpublish.tpl");
$Result["path"] = array
    (
    array
        (
        "url"   => "/view",
        "text"  => "View"
        )
    );
?>

Kristof Coomans

Friday 13 October 2006 12:37:30 am

Hello Luis

Did you try this?

// Method 6
$http =& eZHTTPTool::instance();
$http->setSessionVariable( 'stuff', $stuff );
return $Module->redirectTo( '/path/to/somewhere' );

I advice you to upgrade to a more recent release of the 3.6 branch, the one you are using is really old.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luis Cruz

Friday 13 October 2006 6:36:42 am

@Kristof

Nope, that didn't work either. The other methods redirected to the second extension, but this one didn't even do that.

Thanks though; I'll look into the code for the module redirect and see if there is something else in or around it that might be useful to try.

Cheers.

Claudia Kosny

Friday 13 October 2006 1:42:11 pm

Hi Luis

I jus tried Kristofs suggestion on EZ 3.8.4 and it works fine. The module redirects the the other extension and this extension can see the session parameters that I set in the first extension. Although this will not help you much with your current problem it might be an incentive to upgrade ;-)

Good luck

Claudia

Luis Cruz

Wednesday 01 November 2006 10:20:22 am

Upgrading to the latest version of eZ turned out to not be the solution to my problem (now on 3.6.11). I was misunderstanding how eZ was handling session information; this helped me clear up one issue. However, my primary issue remains. Here is the flow step by step.

1. End up on page /foo. This page contains a form.

2. Plug in values into the form and submit.

3. The form submits to the same page, /foo.

4. /foo detects that the form has been submitted and calls function validate()

5. Based on the form data, validate() sets certain session variables.

6. validate() finally does a header("Location: /bar");

7. Arriving at /bar shows that the session variables have vanished.

I've put debug statements nearly everywhere. In between steps 5 & 6, I dump out the entire $_SESSION variable to a log file. It shows that my variables are set. However, dumping $_SESSION out on step 7 shows that the variables set in the validate() function on /foo have disappeared.

I've also tried placing eZSessionStop() calls in various places (e.g., after setting my variables in validate() ) to flush things out, but that has not brought success either. Very stumped at this point.

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 18 2025 20:58:34
Script start
Timing: Jan 18 2025 20:58:34
Module start 'layout'
Timing: Jan 18 2025 20:58:34
Module start 'content'
Timing: Jan 18 2025 20:58:35
Module end 'content'
Timing: Jan 18 2025 20:58:35
Script end

Main resources:

Total runtime0.7658 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.1719152.6563
Module start 'layout' 0.00800.0038 740.828139.5078
Module start 'content' 0.01170.7527 780.3359600.9453
Module end 'content' 0.76440.0013 1,381.281316.0938
Script end 0.7657  1,397.3750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.4982160.0002
Check MTime0.00160.2150160.0001
Mysql Total
Database connection0.00090.123110.0009
Mysqli_queries0.699491.3298650.0108
Looping result0.00080.1075630.0000
Template Total0.728395.120.3641
Template load0.00240.318920.0012
Template processing0.725894.782320.3629
Template load and register function0.00020.028610.0002
states
state_id_array0.00090.123810.0009
state_identifier_array0.00120.153220.0006
Override
Cache load0.00210.2781340.0001
Sytem overhead
Fetch class attribute can translate value0.00070.089330.0002
Fetch class attribute name0.00120.155160.0002
XML
Image XML parsing0.00090.114430.0003
class_abstraction
Instantiating content class attribute0.00000.001760.0000
General
dbfile0.00080.1082160.0001
String conversion0.00000.001540.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
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 16
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs