Home > php教程 > PHP源码 > body text

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

PHP中文网
Release: 2016-05-25 17:08:28
Original
1097 people have browsed it

统一入口处理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;
        }
    }

}
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!