1
yingzhao
session management with XOOPS environment (appreciate your help)
  • 2008/5/18 17:52

  • yingzhao

  • Just popping in

  • Posts: 45

  • Since: 2008/5/12


Hello everyone,

This is my first post in the forum. If I placed my question in the wrong place, pardon, si vous plait.

I am trying to integrate my own php scripts with XOOPS-2-0-18-1. What I did was.

1. place my scripts into a folder in the XOOPS folder, where XOOPS is installed.
2. add the snippet.
<?php
include("../mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");
?>
at the beginning of my own script
3. add the snippt.
<?php
include(XOOPS_ROOT_PATH."/footer.php");
?>
at the end of my script.

I get the same look & feel executing my scripts as well as the rest of the XOOPS content.

Now, in my own script, I use php session to pass data, while user navigating through pages. Within my own scripts, my session is handled in the following way.

function register($name, $val)
{
if (!isset($_SESSION))
{
session_start();
}
$_SESSION[$name] = $val;
}
function retrive($name)
{
if (!isset($_SESSION))
{
session_start();
}
if (isset($_SESSION[$name]))
{
return $_SESSION[$name];
}
else
{
return null;
}
}

Notice that I do not store class or object, or anything fancy along that line into my session. These functions are used to store and retrive simple name and value pairs.

After integrated my application with XOOPS as a whole site, I performed testing on two local php environments (both are packaged in xampp), php 5.1.1 and php 5.2.5. The whole site works perfectly fine.

However, when I deployed this same application on my hosting server (php 4.4.8). It seems that in my own scripts, the session data is not preserved, while a user navigating through these pages.

If I add a php script block

<?php
session_start();
?>

at the very first line of my script, that is, before the

<?php
include("../mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");
?>

when the user navigate to my php script, a new session will be created. And as long as the user is navigating within the scope of my own application, session data that is managed by my own php scripts can be stored and retrived perfectly fine. In other words, at this point, the session that was created in the XOOPS site (for example, after user logged in, the uid, group info are stored in this session) is not available. Then, as soon as the user navigate outside of my application scope, the XOOPS site session is again available, but the session created within my script is not available.

The only session configuration difference between my local and my host environments that I spotted is that my local uses "files user sqlite" as "Registered save handlers", while my host uses "files user". I have already asked my host to investigate whether that makes any difference.

Other than that, can someone here tell me whether there is a build in session management mechanism that I can safely make use of. Or any suggestion what I had done wrong with my own session usage in my code?

BTW, I had done search home work, no success in finding a solution.

Many thanks for your assistance. Merci a tous.

2
yingzhao
Re: session management with XOOPS environment (appreciate your help)
  • 2008/5/19 17:02

  • yingzhao

  • Just popping in

  • Posts: 45

  • Since: 2008/5/12


I lost a three-day long weekend to nail this problem, and to find a workaround for it.

It turns out the XOOPS uses a custom session save handler to store session in MySQL db. Theoritically, this custom handler should be loaded, when my script execute the main.php, which is the case in my test environments. Unfortunately, in the web hosting environment, this custom handler is failed to be loaded in my script execution. Thus, leading to the problem that appears that my own scripts can not share the same session with the rest of XOOPS...

As a workaround, I commented out the line of code session_set_save_handler to force XOOPS fall back to use the defaul file based session handler. For now, things look like start to fall in places.

Still can not get my head around the enigma why the custom handler fails to load. It would be nice to have my session data stored in db, rather than the public /tmp.

Login

Who's Online

195 user(s) are online (118 user(s) are browsing Support Forums)


Members: 0


Guests: 195


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits