aleX_hill Posted January 5, 2007 Share Posted January 5, 2007 I am haveing a few problems with session variables.I can set them properly, and use them in scripts etc, however when I use a standard variabel with the same name as the session variable, it seems to override it.For example:[code]$_SESSION['name'] = "value";$name = "value2";echo $_SESSION['name'];[/code]will print "value2".Anyone know why?Thanks in advance,Alex Quote Link to comment https://forums.phpfreaks.com/topic/32948-setting-session-variables/ Share on other sites More sharing options...
Gruzin Posted January 5, 2007 Share Posted January 5, 2007 It does display [b]value[/b].... everything works correctly.Regards,George Quote Link to comment https://forums.phpfreaks.com/topic/32948-setting-session-variables/#findComment-153427 Share on other sites More sharing options...
aleX_hill Posted January 5, 2007 Author Share Posted January 5, 2007 Thanks George,I can assure you that with the hosting that I am using, it does not work correctly.It does seem to work if that is the only code in the file, however in the following instance it does not (and it is not the only instance).[code]<?phpsession_start();include("includes/header.php");include("login_functions.php");include("includes/checklogin.php"); $admin_code = $_GET['admin_code']; if ($admin_code == "admin_home" || $admin_code == NULL) { $_SESSION['test'] = "value1"; $test = "value2"; echo $_SESSION['test']; include("/dir/file.php"); } else { include("file1.php"); include("file2.php"); include("file3.php"); include("file4.php"); } include("navigation.php"); include("includes/footer.php");?>[/code]The above code spits out "value2" on the echo line.Alex. Quote Link to comment https://forums.phpfreaks.com/topic/32948-setting-session-variables/#findComment-153451 Share on other sites More sharing options...
Gruzin Posted January 5, 2007 Share Posted January 5, 2007 Well, to tell you the truth I don't really get why it doesn't work... Did you try to change the [b]$test[/b] variable name? Quote Link to comment https://forums.phpfreaks.com/topic/32948-setting-session-variables/#findComment-153453 Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2007 Share Posted January 5, 2007 Sounds like a register_globals problem. See the following from the php manual -[quote]If register_globals is enabled, then the global variables and the $_SESSION entries will automatically reference the same values which were registered in the prior session instance. However, if the variable is registered by $_SESSION then the global variable is available since the next request. [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/32948-setting-session-variables/#findComment-153604 Share on other sites More sharing options...
wildteen88 Posted January 5, 2007 Share Posted January 5, 2007 Yeah this sounds like a register_globals problem. When register global's is enabled it allows you to use the key to the super_global array as the name for the variable. For example you can use $name or $_SESSION['name'] to write/read to the session named name.Regsiter globals is now set to off by default as of PHP4.2 as it can cause security exploits within your code. regsiter_globals will soon be gone for good as of PHP6 (thank god).If your host allows you to use .htaccess files then I would recommend you add the following to a .htaccess file in your document root (the place where you upload your files to) with the following code in it:[tt]php_flag register_globals off[/tt]That should turn register_globals off throughout your website.For more information on register globals please read [url=http://uk2.php.net/register_globals]this page[/url] Quote Link to comment https://forums.phpfreaks.com/topic/32948-setting-session-variables/#findComment-153622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.