POST and GET method WEB PHP
02 Nov 2011 Leave a Comment
in php
in website, method to sending variable is divide two
first GET, if you looking the url bar like http://somedomain.com/index.php?value=given
value=given is the variable which sending with method get, we can read it trough
second POST, you cannot see the value without some technique or tools
PHP know all this method and divide they two with method $_GET and $_POST to handle the value
notice this:
when you send value with method GET you must use $_GET method to get the value, and same with POST
in some case, you have build some function with method GET or POST (but not both) to get value, and forward it to algorithm, if you work the method with structural programming, you design the function can use / work with other module or function or class, sometimes you need to switch method from GET to POST or otherwise
solution:
you build some method to doing two method getting variable,
Algorithm: use first method, check it, if not set, use second method
function notEmpty($str='id', $d){
if(!isset($id)) $id = $_GET[$str];
if(empty($id)) $id = $_POST[$str];
if(empty($id)){
if(empty($d) && !isset($d))
die("empty value $str, stop the operation");
else
return $d;
} else return $id;
}
this is like open global variable, so you must carefully use this, just use if ‘URGENT’
