- PHP session side-effect warning with global variables as a source of data
- Answer by Melody Pierce
- Answer by Dustin McPherson
- Answer by Jonah Pittman
- Answer by Hayes Beasley
- Answer by Keira Juarez
- Answer by Milena Watkins
- Answer by Aleena Porter
- PHP session side-effect warning with global variables as a source of data
- Solution 2
- Solution 3
- Solution 4
- Solution 5
PHP session side-effect warning with global variables as a source of data
http://www.spiration.co.uk/post/1231/Your-script-possibly-relies-on-a-session-side-effect,Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0,This is good information on finding out what’s causing the warning, but I would recommend NOT shutting off the warnings Owen mentions. These runtime functions are removed in PHP 5.4.0 and the developer should get into the practice of avoiding such usage of variables.,basically you have a variable with the same name as your session. ex:
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);
Answer by Melody Pierce
I’m trying to host a PHP web site that was given to me. I see this warning:,Follow the same structure for starting the session in all your files using sessions.,Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0,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:
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);
Answer by Dustin McPherson
I’m trying to host a PHP web site that was given to me. I see this warning:,basically you have a variable with the same name as your session. ex:, php — session — session-variables — global-variables ,Or vise-versa just as long as the session name and the variable name are different. Think of it this way: when you upgrade to the latest build, you’ll have to debug your code anyhow.
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);
Answer by Jonah Pittman
I actually blog as well and I am creating a little something related to this blog post, “Your script possibly relies on a session side-effect which existed until PHP 4. 2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session., [full error message: «Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively.» ],Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0,Which PHP version you are using? Also, are you using register_globals in your project?
[full error message:«Your script possibly relies on a session side-effect which existed
until PHP 4.2.3. Please be advised that the session extension does
not consider global variables as a source of data, unless
register_globals is enabled. You can disable this functionality and
this warning by setting session.bug_compat_42 or
session.bug_compat_warn to off, respectively.»
]
[full error message: "Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively." ]
Answer by Hayes Beasley
This is a ‘superglobal’, or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods. , An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used. ,session_start() — Start new or resume existing session,$_SESSION — Session variables
Creating New Session==========================Getting Session==========================Updating Session==========================Deleting Session==========================Reference: http://gencbilgin.net/php-session-kullanimi.html
Answer by Keira Juarez
basically you have a variable with the same name as your session. ex:,By enrolling in this course, you will get access to ALL of my current and future courses for the lowest possible discount we as instructors are capable of offering on Udemy — FOREVER. ,these values can be set in php.ini or .htaccess as well,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:
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);"
Answer by Milena Watkins
basically you have a variable with the same name as your session. ex:,I think the buggy part has to do with that $_SESSION bug (or side-effect) that treats unitialized variables in $_SESSION as global variables. See this SO question. Changing the name of the session variable to something else will remedy this.,Reducing font size in table so the table fits inside a div,these values can be set in php.ini or .htaccess as well
Update: I can reproduce half of your test case on PHP 5.3.1 but only if I have register_globals set to On:
session_start(); // obviously class Plate // to have something on my plate < var $Member1; var $Member2; >$plate = new Plate(); $plate2 = clone $plate; echo gettype($plate); // Prints "object" echo gettype($plate2); // Prints "object" $_SESSION['plate'] = serialize($plate); echo gettype($plate); // Prints "string" echo gettype($plate2); // Prints "object", unlike in your example $plate = new Plate(); $plate2 = new Plate(); echo gettype($plate); // Prints "object" echo gettype($plate2); // Prints "object" $_SESSION['plate'] = serialize($plate); echo gettype($plate); // Prints "string" echo gettype($plate2); // Prints "object", unlike in your example
I think the buggy part has to do with that $_SESSION bug (or side-effect) that treats unitialized variables in $_SESSION as global variables. See this SO question. Changing the name of the session variable to something else will remedy this.
$_SESSION['session_plate'] = serialize($plate); // $plate will remain unharmed
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);
Answer by Aleena Porter
Which I’m assuming means I need to change one of my variable names so it doesn’t conflict with the session variable right? That’s what I read, but I’m not sure which one to change.,Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0,You better start on getting rid of deprecated functions such as session_register().,Note** this option does not delete the question immediately,Since others contribution also matters and security reasons.Your request will be Queued.We will review the question and remove.It may take some days.
I’m fairly new to php, and am sure this is easy, but I’d like to do it the right way. I have this script:
else < $username=$_POST["username"]; $password=$_POST["password"]; session_start(); if ($username=="bob" AND $password=="123")< $permission="yes";>$username=$_POST["username"]; session_register("permission"); session_register("username"); if ($permission=="yes") < // Show stuff >> ?>
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
Solution 2
There seem to be a few problematic possibilities here:
says that cases like this:
$_SESSION['firstname']=$_REQUEST['firstname'];
Additionally, I interpret this php bug content: http://bugs.php.net/bug.php?id=41540 to mean that this error may also occur when you assign a variable to the session superglobal that is not yet initialized, e.g.
//Start of script $_SESSION['bob'] = $bob;
Solution 3
This is good information on finding out what’s causing the warning, but I would recommend NOT shutting off the warnings Owen mentions. These runtime functions are removed in PHP 5.4.0 and the developer should get into the practice of avoiding such usage of variables.
To fix this, it may be a pain on the developers end, but if you have
Or vise-versa just as long as the session name and the variable name are different. Think of it this way: when you upgrade to the latest build, you’ll have to debug your code anyhow.
Solution 4
When you are making changes to the .htaccess ini_set does not work. You will need to do it as:
php_flag session.bug_compat_42 0 php_flag session.bug_compat_warn 0
Solution 5
in my case, php.ini change from on to off
session.bug_compat_42 = off session.bug_compat_warn = off
if not working, restart apache