Home  >  Article  >  php教程  >  统一获取设置get和post数据的类

统一获取设置get和post数据的类

PHP中文网
PHP中文网Original
2016-05-25 17:08:281107browse

统一入口处理get post 数据有利于统一的控制传递的参数,进行过滤、修改该等操作。

1. [代码][PHP]代码   

<?php
class context {
    /**
     * 获取 设置参数
     * @param $key
     * @param null $value
     * @param null $default
     * @todo 获取GET POST的值和设置值的方法
     * @author  http://www.php.cn/
     * @return null
     */
    static public function get($key, $value = NULL, $default = NULL) {
        if ($value == NULL) {
            if (isset($_GET[$key])) {
                return $_GET[$key];
            } else if (isset($_POST[$key])) {
                return $_POST[$key];
            } else {
                return $default;
            }
        } else {
            $_GET[$key] = $value;
            $_POST[$key] = $value;
        }
    }

}

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn