Zblog Get GetVars(), a function that passes values such as GET/POST/COOKIE

Zblog Tutorial six hundred and eighty-three

PHP usually uses $_REQUEST $_GET $_POST or $_COOKIE Variables, and generally isset() It is a little troublesome to judge whether the variable is declared. Z-Log encapsulates the function of PHP's HTTP Request method GetVars() The code is simplified, the value can be obtained quickly, and there is no need to isset() It is judged that null is returned by default when the variable does not exist, and optional parameters of the default return value are also provided, which is relatively convenient and easy to use.

GetVars() function syntax

 one
 Mixed GetVars ( $name ,  $type  =  'REQUEST' )
Parameter Description
  • $name – string, the name value to be obtained, required
  • $type – string, method type, default REQUEST, or select GET, POST or COOKIE
Return value

When the parameter receives the passed value, it returns the assignment; otherwise, it returns null.

Code example

 one two three four
 $filename  = GetVars ( 'filename' , 'POST' ) ;
 if  (  is_null ( $filename )  ) {
   echo  "File name cannot be empty" ;
 }
Tips
  • Be careful to use is_null Judge whether the relevant value is obtained;
  • In fact, the second parameter is not case sensitive, but it is usually recommended to use uppercase.

Official wiki: https://wiki.zblogcn.com/doku.php?id=zblogphp:development:functions:getvars

Highlight: