RANGER
RANGER

Reputation: 1691

PHP session extension does not consider global variables

I am currently getting the error:

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

I believe it has something to do with the following code (since that is when I started noticing it):

session_start();                         // Open sessions
$remember_alert = $_SESSION['alert'];   // Remember session alert
session_unset();                         // Unset all data in session
session_destroy();                     // Kill empty session
session_start();                         // Re-open session
$_SESSION['alert'] = $remember_alert;   // Recall session alert

This is code on the logoff.php page of a CMS I am building and is used to clear all session info except the alert variable. Any insight would be greatly appreciated!

Upvotes: 3

Views: 3822

Answers (1)

alex
alex

Reputation: 490243

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().

Upvotes: 5

Related Questions