[dokuwiki] Re: Session variables being reset?

  • From: Raam Dev <raamdev@xxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Tue, 05 Dec 2006 16:24:21 -0500

Apologies. My previous code was a little buggy. You need to call start_session() after you change the session_name():


<?php
   session_name("PHPSESSID");
   session_start();
   echo $_SESSION['myvar'];

   session_name("DokuWiki");
   session_start();
?>


Raam Dev wrote:

I figured out the problem. Hopefully this info will help someone else who runs across this issue.

DokuWiki creates a new session name called DokuWiki, so any session variables created and set using the default session name of PHPSESSID will not be accessible unless you first change the session name. Here is how I resolved my problem in /lib/tpl/default/main.php:

<?php
...
echo session_name(); // displays "DokuWiki"
session_name("PHPSESSID"); // change session name back to the default
echo session_name(); // displays "PHPSESSID"

echo $_SESSION['myvar']; // displays "abc123"

session_name("DokuWiki"); // set session name back to DokuWiki in case DokuWiki needs it
...
?>

Raam


Raam Dev wrote:

On test.php I have the following:

<?php
session_start();
$_SESSION['myvar'] = "abc123";
?>

Then, from anywhere within DokuWiki, for example at the top of /lib/tpl/default/main.php, I add the following:

session_start();  // tried with and without this line
echo $_SESSION['myvar'];

The session variable appears to be empty and does not echo "abc123". However, if I add the following to main.php:

session_start();
$_SESSION['myvar'] = "abc123";
echo $_SESSION['myvar'];

everything works as expected. Why wouldn't the session variables carry over when they're set on a page outside DokuWiki? Am I missing something?

Thanks!
Raam




--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: