PHP session side-effect warning with global variables as a source of data
basically you have a variable with the same name as your session. ex:
$_SESSION['var1'] = null;
$var1 = 'something';
which will reproduce this error. you can stop PHP from trying to find existing variables and warning you about them by adding these lines to your script:
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);
these values can be set in php.ini or .htaccess as well
Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3
There is a session variable given the same name as some existing global variable (i.e. both $_SESSION['name']
and $name
exists).
Rename either of them.
It should be a quite duplicate question, as it just occurred to me.
PHP session side-effect warning - how to get solve?
It is happening because of
session_register("username");
It is not recommended, and deprecated as of PHP 5.3.
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.
Source.
As we all know, register_globals
is terrible, and should always be off.
The most common way to register a session var is with the $_SESSION
superglobal, i.e.
$_SESSION['username'] = $username;
PHP session side-effect warning with global variables as a source of data
basically you have a variable with the same name as your session. ex:
$_SESSION['var1'] = null;
$var1 = 'something';
which will reproduce this error. you can stop PHP from trying to find existing variables and warning you about them by adding these lines to your script:
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);
these values can be set in php.ini or .htaccess as well
PHP Session warning issue
This means you have a variable with the same name as your session variable is as below.
$_SESSION['variable'] = null;
$variable = 'data';
You can stop PHP from trying to find existing variables and warning you about them by adding these lines to your script in php.ini or .htaccess
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);
PHP declaring global and session variables
Try setting session.bug_compat_42
to off, it will turn off the functionality the warning is about. c.f. http://php.net/manual/en/session.configuration.php
PHP session extension does not consider global variables
Hi, I had the same problem, and in my
case it was here $arrFormData and here
$_SESSION['arrFormData'] The thing is
having the same variable name. In my
case it happened on a $_GET array,
but I guess it should be similar. Give
it a try on renaming the $arrFormData
variable to something else and let us
know if it worked.
Source.
It is because somewhere you have the same variable name as the key of your $_SESSION
global.
Example
session_start();
$_SESSION['a'] = 1;
$a = 1;
You can disable the error by turning session.bug_compat_42
off in your php.ini
or using ini_set()
.
How can I avoid PHP session errors?
If your variable names are the same as the session parameters then this version of PHP will incorrectly recognize this as the programmer incorrectly relying on register_globals for session variables. Rename your variables and the warning should go away.
$mySessionVar = $_session["sessionVar"];
and not
$sessionVar = $_session["sessionVar"];
Related Topics
Php, Display Image with Header()
Memcached VS Apc Which One Should I Choose
Reconstruct/Get Source Code of a PHP Function
Sum Values in Foreach Loop PHP
Int((0.1+0.7)*10) = 7 in Several Languages. How to Prevent This
Laravel Eager Loading with Limit
PHP Artisan Make:Auth Command Is Not Defined
Getting ’ Instead of an Apostrophe(') in PHP
Echo a Multidimensional Array in PHP
Best Practice to Generate Random Token for Forgot Password
Adding Attributes to Customer Entity
PHP Create a Multidimensional Array from an Array with Relational Data