0

This is a quick question, that has been bugging me for quite some time!

I have a pagewww.example.com/dir/index.php which sets a $_SESSION variable. I access this variable again on www.example.com/dir/dir2/dostuff.php and this works fine!

However, if I set the session through www.example.com/dir/ it isn't set in www.example.com/dir/dir2/dostuff.php.

I have rewritten the .htaccess with

RewriteRule ^.*\/dir\/$ /dir/index.php [NC]

and set my php.ini in index.php using:

ini_set('session.cookie_domain', '.example.com');

However without results. Does anyone have any suggestions?

Update:

In a nutshell index.php simply runs:

if (!isset($_SESSION)) session_start();
$_SESSION['param'] = "val";

The dostuff.php runs:

if (!isset($_SESSION)) session_start();
echo $_SESSION['param'];
UnholyRanger
  • 1,977
  • 14
  • 24
Andreas Jarbol
  • 745
  • 2
  • 11
  • 27

1 Answers1

0

From session_start

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

You should call session_start() unconditionally, when you want to access _SESSION variables.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198