Solved

php session variables auto load

Posted on 2009-05-12
3
330 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:erenpasa
3 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24363233
0
 
LVL 11

Expert Comment

by:VanHackman
ID: 25699437

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!    
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question