Php getpost and other large variable generation processes. · Author: laruence (www.laruence.com) · address of this article: www.laruence.com20081107581.html. please indicate the source to discuss the generation process of PHP large variables. In addition
By laruence (http://www.laruence.com /)
· Address: http://www.laruence.com/2008/11/07/581.html
· Reprinted, please indicate the source
This article mainly discusses the generation process of PHP large variables. In addition, if you notice that the input name submitted in the form contains a bit of a number, it is automatically converted into an underscore in PHP. And you want to know why and when it happened? This article also answers this question.
First of all, it is clear that the PHP variable name cannot contain the vertex number. However, to process the Dot name in the form, PHP automatically converts the dot (.) to an underscore (_).
To understand how PHP is handled, first we need to understand the construction process of variables such as $ _ GET, $ _ POST, and $ _ COOKIE.
After each request arrives, apache sends control to the PHP module when processing the response stage, the PHP module will call php_request_startup indirectly before processing the request (the specific call sequence is send_php-> apache_php_module_main-> php_request_startup. for details about this department, see my previous article (PHP Life Cycle ), in php_request_startup:
Int
Php_request_startup (TSRMLS_D)
{
Int
Retval = SUCCESS;
# If PHP_SIGCHILD
Signal (SIGCHLD, sigchld_handler );
# Endif
If
(Php_start_sapi () = FAILURE)
{
Return
FAILURE;
}
Php_output_activate (TSRMLS_C );
Sapi_activate (TSRMLS_C );
Php_hash_environment (TSRMLS_C );
Zend_try
{
PG (during_request_startup) = 1;
Php_output_activate (TSRMLS_C );
If
(PG (expose_php ))
{
Sapi_add_header (SAPI_PHP_VERSION_HEADER, sizeof (SAPI_PHP_VERSION_HEADER)-1, 1 );
}
}
Zend_catch
{
Retval = FAILURE;
}
Zend_end_try ();
Return
Retval;
}
Note that the php_hash_environment (TSRMLS_C) function is called. This function is the function that initializes the request-related variables before Request processing.
This function is defined in main/php_variables.c. if you are interested, see:
Int
Php_hash_environment (TSRMLS_D)
{
Char * p;
Unsigned
Char
_ Gpc_flags [5] = {0, 0, 0 };
Zend_bool
Jit_initialization = (PG (auto_globals_jit )&&! PG (register_globals )&&! PG (register_long_arrays ));
Struct
Auto_global_record
{
Char * name;
Uint
Name_len;
Char * long_name;
Uint
Long_name_len;
Zend_bool
Jit_initialization;
}
Auto_global_records [] = {
{
"_ POST", sizeof ("_ POST"), "HTTP_POST_VARS", sizeof ("HTTP_POST_VARS"), 0
},
{
"_ GET", sizeof ("_ GET"), "HTTP_GET_VARS", sizeof ("HTTP_GET_VARS"), 0
},
{
"_ COOKIE", sizeof ("_ COOKIE"), "HTTP_COOKIE_VARS", sizeof ("HTTP_COOKIE_VARS"), 0
},
{
"_ SERVER", sizeof ("_ SERVER"), "HTTP_SERVER_VARS", sizeof ("HTTP_SERVER_VARS"), 1
},
{
"_ ENV", sizeof ("_ ENV"), "HTTP_ENV_VARS", sizeof ("HTTP_ENV_VARS"), 1
},
{
"_ FILES", sizeof ("_ FILES"), "HTTP_POST_FILES", sizeof ("HTTP_POST_FILES"), 0
},
};
Size_t
Num_track_vars = sizeof (auto_global_records)/sizeof (struct
Auto_global_record );
Size_t
I;
/* Jit_initialization = 0 ;*/
For
(I = 0; I {
PG (http_globals) [I] = NULL;
}
For
(P = PG (variables_order); p & * p; p ++)
{
Switch (* p)
{
Case
P:
Case
P:
If
(! _ Gpc_flags [0] &! SG (headers_sent) & SG (request_info). request_method &&! Strcasecmp (SG (request_info). request_method, "POST "))
{
Sapi_module.treat_data (PARSE_POST, NULL, NULL
TSRMLS_CC);/* POST Data */
_ Gpc_flags [0] = 1;
If
(PG (register_globals ))
{
Php_autoglobal_merge (& EG (symbol_table), Z_ARRVAL_P (PG (http_globals) [TRACK_VARS_POST])
TSRMLS_CC );
}
}
Break;
Www.devdao.com is omitted below:
}}}
In php. ini, you can use variables_order to control whether PHP generates a large variable.
About the order, that is, if auto_register_globals is enabled, if p is processed and g is processed first, $ _ GET [a] will overwrite $ _ POST [a];
As you can see, this is not far from success. sapi_module.treat_data is also php_default_treat_data,
In php_default_treat_data, all variables call php_register_variable_safe to register the variables. php_register_variable_safe will eventually call php_register_variable_ex:
PHPAPI
Void
Php_register_variable_ex (char * var, zval * val, zval * track_vars_array
TSRMLS_DC)
{
Char * p = NULL;
Char * ip;/* index pointer */
Char * index, * escaped_index = NULL;
Int
Var_len, index_len;
Zval * gpc_element, ** gpc_element_p;
Zend_bool
Is_array = 0;
HashTable * symtable1 = NULL;
Assert (var! = NULL );
If
(Track_vars_array)
{
Symtable1 = Z_ARRVAL_P (track_vars_array );
}
Else
If
(PG (register_globals ))
{
Symtable1 = EG (active_symbol_table );
}
If
(! Symtable1)
{
/* Nothing to do */
Zval_dtor (val );
Return;
}
/*
* Prepare variable name
*/
/* Ignore leading spaces in the variable name */
While
(* Var & * var =
)
{
Var ++;
}
/* Ensure that we dont have spaces or dots in the variable name (not binary safe )*/
// Pay special attention to the following section ....
For
(P = var; * p; p ++)
{
If
(* P =
| * P = .)
{
* P = _;
}
Else
If
(* P = [)
{
Is_array = 1;
&
Author: laruence (http://www.laruence.com/) · Address: http://www.laruence.com/2008/11/07/581.html · reprinted please indicate the source of the main discussion of the PHP large variable generation process. In addition...