1

Occassionaly I run accross this error in PHP, how can I fix this or what cause it?

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

4
  • You'll need to paste some code; i.e., what is line 0 Commented Aug 7, 2009 at 19:03
  • It might not be line 0, but some code will help. Commented Aug 7, 2009 at 19:05
  • thats a tough one my site is compile of hundreds of pages but generally my header file is first and this error usually only shows up on some pages after I post something with a form then redirect to a page Commented Aug 7, 2009 at 19:07
  • I fixed it, some pages show a session message sitewide when I need to show a user a custom message, it then shows the session value then unsets the session, the problem was I was unsetting the session by assigning it a blank value, now I use unset($_SESSION['sess_msg']); and the error is gone Commented Aug 7, 2009 at 19:33

5 Answers 5

6

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"]; 
Sign up to request clarification or add additional context in comments.

1 Comment

Interesting. I never checked out session.bug_compat_42 before. +1 for you and Gumbo.
2

You are relying on a deprecated feature of PHP, called register_globals. This feature caused many security issues, and shouldn't be used any longer. The PHP manual discusses this in-depth.

For an excellent description of the problem, see this Google Groups post.

Edit: If you aren't relying on register_globals, then you should pay attention to Gumbo and stereointeractive's answers.

Comments

1

Just disable session.bug_compat_42 and session.bug_compat_warn as the error message suggests.

2 Comments

Error messages exist for a reason and shouldn't be disabled during developemtn. At least make sure you understand why you're getting an error message before you disable it.
OK, now that I read stereoactive's advice I see why you might disable in this one case.
0

I would NOT suggest you disable the warnings or error messages, this is a problem you probably want to fix. Either you have variables names that are triggering bogus error message (see sterrointerative.com's answer) or you're trying to use global variables without defining them (which means you likely have bugs you can't see). In my opinion that's an important difference you want to sort out.

If it's only happening on some pages, you're likely going to have to review all the code pulled into those pages and search for use of variables that don't appear to be defined before they are used. Stepping through those pages with a debugger ought to help.

1 Comment

I store messages like error messages into a session variable, on a page load if this session is not null I display it, then I unset the session variable right after showing it, I notice this error only happens sometimes but everytime it does happen it is right after one of my messages is shown and then it will not unset it on that page either when this error occurs
-5

error_reporting(0) disables all error messages.

1 Comment

This is not a good solution. It will only hide issues with your code, and lead to future problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.