Home > php教程 > php手册 > php中直接获取变量值[post,get,cooie]而不$_GET 字符转义

php中直接获取变量值[post,get,cooie]而不$_GET 字符转义

WBOY
Release: 2016-05-25 16:47:09
Original
1337 people have browsed it

本文章介绍了一个全局的也是大家常用的一个php获取变量值的方法,有需要的朋友可以参考一下.

实例代码如下:

<?php
function my_addslashes($string, $force = 0) {
    !defined(&#39;MAGIC_QUOTES_GPC&#39;) && define(&#39;MAGIC_QUOTES_GPC&#39;, get_magic_quotes_gpc());
    if (!MAGIC_QUOTES_GPC || $force) {
        if (is_array($string)) {
            foreach ($string as $key => $val) {
                $string[$key] = my_addslashes($val, $force);
            }
        } else {
            $string = addslashes($string);
        }
    }
    return $string;
}
foreach (array(
    &#39;_COOKIE&#39;,
    &#39;_POST&#39;,
    &#39;_GET&#39;
) as $_request) {
    foreach ($$_request as $_key => $_value) {
        $_key{0} != &#39;_&#39; && $$_key = my_addslashes($_value);
    }
}
echo $urls;
?>
Copy after login

这里我们利用了foreach 来遍历变量判断是否cookie,post,get方法,这样我使用时只要直接使用my_addslashes程序会自动区别是来自post,get,cookie的值.


教程网址:

欢迎收藏∩_∩但请保留本文链接。

Related labels:
get
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