· Author: laruence (http://www.laruence.com/)
· This address: http://www.laruence.com/2008/11/07/581.html
· Reprint please indicate the source
This paper mainly discusses the process of generating large variables in PHP. In addition, if you notice that when a number is in the name of input that is submitted in the form, the dot is automatically processed into an underscore in PHP. And you want to know why, when did it happen? Oh, this article has also answered the question.
First, make a clear question, PHP variable name is not included in the dot number. But in order to process the name of the dot in the form, PHP automatically puts the dot (.) number Convert to an underscore (_).
To know how PHP is handled, first we need to understand, $_get, $_post, $_cookie and other variables of the construction process.
After each request arrives, Apache processes the response phase, the control is handed over to the PHP module, and the PHP module calls Php_request_startup indirectly before processing the request (the specific call sequence is send_php- Apache_php_module_main->php_request_startup, about this department can 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 the php_hash_environment (tsrmls_c) function call, which is the function that initializes the request-related variables before the request is processed.
This function is defined in: MAIN/PHP_VARIABLES.C, which is interesting to look at:
Int
Php_hash_environment (Tsrmls_d)
{
Char*p;
Unsigned
Char
_gpc_flags[5]={0,0,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: br> 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;
.... The following ellipsis, www.devdao.com:
}}}
Here's a digression, that is, in php.ini, you can use Variables_order to control whether PHP generates a large variable, the order in which the large variables are generated.
About the order, that is, if the auto_register_globals is opened, if the first process p, post-processing G, then $_get[a], will cover $_post[a];
Can see, not far from success, Sapi_module.treat_data is Php_default_treat_data,
In Php_default_treat_data, for a variable, Php_register_variable_safe is called to register the variable, and Php_register_variable_safe eventually calls 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 has spaces or dots in the variable name (not binary safe) */
//special attention to the following paragraph ....
for
(P=var; *p;p++)
{
If
(*p==
| | *p==.)
{
*p=_;
}
Else
If
(*p==[)
{
Is_array=1;
&
http://www.bkjia.com/PHPjc/508336.html www.bkjia.com true http://www.bkjia.com/PHPjc/508336.html techarticle • Author: laruence (http://www.laruence.com/) • This address: http://www.laruence.com/2008/11/07/581.html reprint please indicate the source This paper mainly discusses the process of generating large variables in PHP. In addition ...