Link to home
Start Free TrialLog in
Avatar of erenpasa
erenpasa

asked on

php session variables auto load

Hi to all,
I have a problem. If session has a variable it create a php variable when i start session?

For example i call my code test.php?test=blabla
after this call session has testMe variable.
after this when i call just test.php there is $testMe php variable?

i think it is a php setting. how can i disable this settign?
Ps: php runs on linux
<?php
session_start();
if (isset($_GET["test"])){
	$_SESSION["testMe"]="Test string...";
	$testMe=$_SESSION["testMe"];
}
echo var_dump($_SESSION);
echo var_dump($testMe)
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

If you set some session variable you can access it using the associative array  "$_SESSION". This session variable is a 'superglobal', or automatic global, variable. This means that it is available in all scopes throughout a script.  So  looks like the variable is "autoloaded" like a php local variable in the script.

To fix this issue, you have two options:

1 - Turn off the "Register Globals" directive editing the php.ini file
2 - Turn off the "Register Globals" with the .htaccess entry: php_flag register_globals off
3 - Use different names for the sessions variables and local variables.

more finfo:

     http://php.net/manual/en/ini.core.php#ini.register-globals

Bye!