Forums / Developer / What is destroying my session cookie?

What is destroying my session cookie?

Author Message

Luis Cruz

Wednesday 26 September 2007 12:21:50 pm

Greetings; running eZ 3.6.11 and am trying to do the following. I have multiple domains each with its own language: foo.com serves up English and foo.de serves up German. We have special content that requires the user to login to access. We want them to be able to login on either site, but we also want to force them to use the English or German site based on their user type.

For example, user A logs into foo.com; their user type/group in eZ is "German User". They attempt to access http://foo.com/special/doc but are redirected to http://foo.de/special/doc. Currently, this interaction is working up to a point; users log in successfully and are redirected successfully. However, the session cookie appears to get destroyed access that login protected page; browsing to another login protected page requires logging in again.

Here are the technical details; first, I have this near the bottom of my pagelayout.tpl:

{beacon()}

This custom operator has the following code:

    function beacon()
    {
        $http =& eZHTTPTool::instance();
        $sessionID = $http->getSessionKey();

        // Salt, Obfuscate, Encrypt, and munge the session ID here...

        $beacon = <<<EOL
<img src="http://foo.com/beacon/(beid)/$sessionID" /><img src="http://foo.de/beacon/(beid)/$sessionID" />
EOL;
    	return $beacon;
    }

As you can see, the purpose of the operator is to embed an image from the various sites that one could log into and access. The image returned will also set a cookie for each site to synchronize the session IDs across the domains.

The code to return this beacon image is this:

include_once("kernel/common/template.php");
$Module =& $Params["Module"];
$Module->setTitle("SSO Beacon");

include_once( "lib/ezutils/classes/ezuri.php" );
$eZURI =& eZURI::instance();
$userParameters = $eZURI->userParameters();

// Was a "type" user parameter set?
if (array_key_exists("beid", $userParameters)) {
    // Pull the header text for the form from the override template
    $sessionID = $userParameters["beid"];

    // reverse the process for munging the session ID...
}

setcookie("eZSESSID" . $GLOBALS['eZCurrentAccess']['name'], $sessionID, time() + 60 * 60 * 24 * 365, "/");
header("Content-type:  image/gif");
readfile("/path/to/pixel.gif");

At the top of pagelayout.tpl is another custom operator that detects what page you are on and redirects you to the appropriate domain. Here is what happens when I step through the process.

1. Go to http://foo.com/user/login; I see that a cookie for foo.com (eZSESSIDen) and for foo.de (eZSESSIDde) is set. Both contain the same session ID value. The beacons (http://foo.com/beacon/(beid)/...) at the bottom of the page contain the same session ID value.

2. Login successfully; cookies and beacons for both domains still contain the same session ID value.

3. Access http://foo.com/special/doc but redirected to http://foo.de/special/doc. HTTP headers for the page hit and redirect show that the cookies sent and received all contain the same session ID value.

4. When http://foo.de/special/doc is finished loading, the .com cookie goes missing, and the beacons on the page all have the session ID set to 0.

5. Moving onto another page now resets the session requiring the user to login again.

So, it seems like the session is being setup correctly when the initial beacon calls are made. When I land on the second domain, it knows that I should be logged in as the proper user and associated with the proper session. However, what is resetting the session ID to 0 when the beacons are included on that page?

I've spun my wheels on this for awhile now and can't seem to get anywhere. Anyone have ideas of where to throw in some debug code or what might be flawed in my approach?

Cheers.

- luis

Luis Cruz

Friday 28 September 2007 6:53:34 am

Never mind... found the issue in the redirect code.

eZ debug

Timing: Jan 18 2025 18:17:11
Script start
Timing: Jan 18 2025 18:17:11
Module start 'content'
Timing: Jan 18 2025 18:17:11
Module end 'content'
Timing: Jan 18 2025 18:17:12
Script end

Main resources:

Total runtime0.9607 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.0077 587.7344180.8281
Module start 'content' 0.00770.7995 768.5625444.6484
Module end 'content' 0.80720.1534 1,213.2109333.7813
Script end 0.9606  1,546.9922 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.4654210.0002
Check MTime0.00150.1598210.0001
Mysql Total
Database connection0.00090.098210.0009
Mysqli_queries0.886292.24701890.0047
Looping result0.00200.20821870.0000
Template Total0.931096.920.4655
Template load0.00190.201120.0010
Template processing0.929196.708620.4645
Template load and register function0.00020.022410.0002
states
state_id_array0.00090.098210.0009
state_identifier_array0.00090.093920.0005
Override
Cache load0.00160.1662240.0001
Sytem overhead
Fetch class attribute can translate value0.00170.171820.0008
Fetch class attribute name0.00180.183120.0009
XML
Image XML parsing0.00040.037120.0002
class_abstraction
Instantiating content class attribute0.00000.000720.0000
General
dbfile0.00530.5524210.0003
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/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 12
 Number of unique templates used: 5

Time used to render debug report: 0.0002 secs