I have three index.php
files in three different folders where each folder (except the base) is a child in another folder. Each file should have its own $_SESSION
array, and should not be overwritten by another path/file.
I just assumed that this would be the case, however, created the following test script, and found this is not the case.
I've also discovered that the session cookie associated with each path is domain "myDomain.com" and path "/".
What is the best way to ensure files in a directory tree each have their own session?
/var/www/html/main.php
<ul>
<li><a href="/testing/cookies">base</a></li>
<li><a href="/testing/cookies/path1">path1</a></li>
<li><a href="/testing/cookies/path1/path2">path2</a></li>
</ul>
<?php
session_start();
echo('<h1>'.$name.'</h1>');
echo('<pre>'.print_r($_SESSION,1).'</pre>');
$_SESSION['test']=$name;
?>
/var/www/html/index.php
<?php
$name='/';
require('main.php')
?>
/var/www/html/path1/index.php
<?php
$name='/path1';
require('../main.php')
?>
/var/www/html/path1/path2/index.php
<?php
$name='/path1/path2';
require('../../main.php')
?>