PHP How to determine whether the value of Get or post is present, this problem has troubled me for a long time, is to use isset or empty or is_array what, please the great God to give a pointing
Reply content:
PHP How to determine whether the value of Get or post is present, this problem has troubled me for a long time, is to use isset or empty or is_array what, please the great God to give a pointing
Isset () is to determine whether the variable is defined, empty () is in the case where the variable is already defined (if the variable is not defined, will be an error variable is undefinded), to determine whether the variable is null, an empty string, empty array is empty () as NULL, Returns True. For example, for example, send a form $user (' name ' = ' Tom ', ' nickname ' = '), you want to Judge $use[' nickname ') is already the user filled out the data, you can use empty () to judge, For example, your form has a password field, but a third-party login registered user temporarily does not have a password field, you need to judge Isset ($user [' Password ']), isset and empty have an essential difference, I hope I can give you an example to help you understand.
You can use $_server[' request_method ' to determine what the request type is.
You can look at the official explanation.
$_server-Server and execution Environment information
Come on, teach me.
$apply _name = isset ($_post[' apply_name ')? $_post[' apply_name ': ';
Or
$apply _name = isset ($_get[' apply_name ')? $_get[' apply_name ': ';
If you don't know even get and post,
$apply _name = isset ($_request[' apply_name ')? $_request[' apply_name ': ';
My personal writing is [check all], so as to avoid all kinds of mistakes. After all, security and comprehensiveness in ordinary projects still use more.
//我所有的项目都有包括一个custom_function.php的公共文件。function check_var( $var, $default = ''){ return( (isset($var) and !empty($var )) ? $var : (!empty($default) ? $default : false) );
First understand the isset, empty, is_null and other variables to determine the function of the functions, and then according to your use of the scene to use the corresponding function:
PHP Empty,isset,is_null Comparison Reference 1
PHP Empty,isset,is_null Comparison Reference 2
PHP Empty,isset,is_null Comparison Reference 3
Variable Judgment Appendix