Go A warning in PHP session

Source: Internet
Author: User
Tags php session

The full text of the warning is as follows:

PHP Warning:Unknown:Your Script possibly relies on a session side-effect

Which existed until PHP 4.2.3. Advised 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

On this issue, there are a variety of solutions on the Internet, but are not know why the answer, then the real reason is what, how to solve it?

Please remember this point first. At PHP4.2 start, Register_globals is set to off by default.

After 4.2.3, in order to be compatible with the previous mode, PHP introduced the bug_compat_42, when this option is enabled (enabled by default), PHP will allow automatic use of variables in the session as global variables. Only if the Bug_compat_warn option is turned on, the feature is reported to be used.

To see a piece of code,

Session_Start ();

Var_dump ($_session);

$name = ' laruence ';

$_session[' name '] = null;

?>

The above code, in the case of bug_compat_42 Open, register_globals off, two times the output of the page refresh, respectively:

First time:

Array (0) {}

Second time

Array (1) {["a"]=> string (8) "Laruence"}

Why the second time is not NULL, because in the case of bug_compat_42 Open, PHP will think that variable A is a reference to $_session[' a '], and when Session_close, the value of variable A is written back.

In this process, if Bug_compat_warn is turned on, it throws a warning at the beginning of the article.

So, that it is~

So, what exactly is the condition of the warning? Knowing these conditions, we can avoid this warning,

In Phpsrc/ext/session/session.c, there are all the answers we want:

static void Php_session_save_current_state (Tsrmls_d)/* {{{* * *

{

int ret = FAILURE;

If_session_vars () {

If there is a session array

if (PS (BUG_COMPAT) &&! PG (register_globals)) {

HashTable *ht = z_arrval_p (PS (http_session_vars));

Hashposition POS;

Zval **val;

int do_warn = 0;

ZEND_HASH_INTERNAL_POINTER_RESET_EX (HT, &pos);

while (ZEND_HASH_GET_CURRENT_DATA_EX (HT

, (void * *) &val, &pos)! = FAILURE) {

if (Z_type_pp (val) = = Is_null) {//variable is NULL

if (Migrate_global (HT, &pos tsrmls_cc)) {//variable write-back

Do_warn = 1;

}

}

ZEND_HASH_MOVE_FORWARD_EX (HT, &pos);

}

if (Do_warn && PS (Bug_compat_warn)) {

Php_error_docref (NULL tsrmls_cc, e_warning, "Your Script possibly

relies on a session side-effect which existed until PHP 4.2.3 ... ");

Omitted after

It can be seen that if you do not turn on bug_compat_42 (which is rarely used now, it will sometimes cause confusion when turned on), or do not start Bug_compat_warn, or you will not see this warning if the register_globals is turned on.

Additionally, if you turn on bug_compat_42, you may also encounter the following notice:

PHP Notice:Unknown:The session Bug compatibility code would not try to

Locate the global variable $324324 due to it numeric nature in Unknown on line 0

This is a warning that may be raised when you use a numeric index in $_session.

Ini

; Whether or not to register the EGPCS variables as global variables. May
; Want to turn this off if you don ' t want to clutter your scripts ' global scope
; With user data.
; You should does your best-write your scripts so, they do not require
; Register_globals to is on; Using form variables as globals can easily lead
; To possible security problems, if the code was not very well thought of.
; Http://php.net/register-globals
Register_globals = Off changed to ON

Go A warning in PHP session

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.