POST and GET method WEB 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’

Published by

G3n1k

just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s