This has been a problem for a while on my computer. I don't know what is going on.
I'm running Xampp on Windows 7 64bit. What would happen is that the PHPSESSID cookie was getting lost. Everything was showing the cookie was getting dropped (debugging saved cookies). I disabled javascript to be sure but I kept losing my session id. I checked the session files and they were there (and saving user credentials).
This is the test that helped discover the issue.
- Code: Select all
if(!defined('INC_DIR')){
define('INC_DIR',str_replace("\\","/",dirname(__FILE__))."/");}
session_start();
if(count($_SESSION['asdf'])>10){array_pop($_SESSION['asdf']);}
$_SESSION['asdf'][]='yes '.rand(1,8109);
exit("<PRE>".print_r($_COOKIE,true)."</PRE>"."<PRE>".print_r($_SESSION,true)."</PRE>");
If you go from a 'fresh start' of xampp above won't work. The PHPSESSID cookie would be lost and the session variables wouldn't last that page view.
- Code: Select all
session_start();
if(count($_SESSION['asdf'])>10){array_pop($_SESSION['asdf']);}
$_SESSION['asdf'][]='yes '.rand(1,8109);
if(!defined('INC_DIR')){
define('INC_DIR',str_replace("\\","/",dirname(__FILE__))."/");}
exit("<PRE>".print_r($_COOKIE,true)."</PRE>"."<PRE>".print_r($_SESSION,true)."</PRE>");
This will work. But I haven't read anywhere that you have to start your session before you define your variables. Its especially weird because it'll start working again later only to randomly stop working again.
I discovered this in my previous install of xampp. I updated and tried again. I then used a virtual host to ensure it wasn't a firefox/cookie issue. I also checked the session files and there was 1 session file for every 'include file' that used a 'define'.
Whats going on here? Is there a php.ini setting I can set to allow session_start and define() to play nice together?