How PHP determines whether a get or post value exists

Source: Internet
Author: User
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

  • 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.