`
fengke86
  • 浏览: 17758 次
  • 来自: ...
社区版块
存档分类
最新评论

php中get_magic_quotes_gpc函数的使用

阅读更多
get_magic_quotes_gpc函数

取得 PHP 环境变数 magic_quotes_gpc 的值。

语法: long get_magic_quotes_gpc(void);

传回值: 长整数

函式种类: PHP 系统功能

内容说明

本 函式取得 PHP 环境设定的变数 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。传回 0 表示关闭本功能;传回 1 表示本功能开启。当 magic_quotes_gpc 开启时,所有的 ' (单引号), " (双引号), \ (反斜线) and 空字符会自动转为含有反斜线的溢出字符。

-----------------------
addslashes -- 使用反斜线引用字符串

描述
string addslashes ( string str)

返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)。

一个使用 addslashes() 的例子是当你要往数据库中输入数据时。例如,将名字 O'reilly 插入到数据库中,这就需要对其进行转义。大多数据库使用 \ 作为转义符:O\'reilly。这样可以将数据放入数据库中,而不会插入额外的 \。当 PHP 指令 magic_quotes_sybase 被设置成 on 时,意味着插入 ' 时将使用 ' 进行转义。

默认情况下,PHP 指令 magic_quotes_gpc 为 on,它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

例子 1. addslashes() 示例
$str = "Is your name O'reilly?";

// 输出:Is your name O\'reilly?
echo addslashes($str);
?>

get_magic_quotes_gpc()
本函数取得 PHP 环境配置的变量 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。返回 0 表示关闭本功能;返回 1 表示本功能打开。当 magic_quotes_gpc 打开时,所有的 ' (单引号), " (双引号), \ (反斜线) and 空字符会自动转为含有反斜线的溢出字符。
分享到:
评论

相关推荐

    php中get_magic_quotes_gpc()函数说明

    get_magic_quotes_gpc函数是一个用来判断是否为用户提供的数据增加斜线了,这个在php.ini配置文件中哦,下面我来介绍一下get_magic_quotes_gpc()函数说明. get_magic_quotes_gpc函数介绍 取得 PHP 环境变数 magic_...

    get_magic_quotes函数详解

    get_magic_quget_magic_quotes函数详解oget_magic_quotes函数详解get_magic_quoget_magic_quotes函数详解get_magic_quotes函数详解get_magic_quotes函数详解get_magic_quotes函数详解tes函数详解get_magic_quotes...

    PHP5下$_SERVER变量不再受magic_quotes_gpc保护的弥补方法

    php $magic_quotes_gpc = get_magic_quotes_gpc(); @extract(daddslashes($_COOKIE)); @extract(daddslashes($_POST)); @extract(daddslashes($_GET)); if(!$magic_quotes_gpc) { $_FILES = daddslashes($_FILES); }...

    深入PHP magic quotes的详解

    特地查看了下手册,关于php magic quotes,常见的几个设置如下,magic_quotes_gpc,magic_quotes_sybase,magic_quote_runtime,这几个函数是在php.ini中去配置的,从手册中可以看出从php5.3后已经废除了这些特性,...

    PHP的特殊字符转译函数使用.pdf

    PHP的特殊字符转译函数使用 get_magic_quotes_gpc() long get_magic_quotes_gpc()

    php参数过滤、数据过滤类

    中开启magic_quotes_gpc和magic_quotes_runtime。magic_quotes_gpc可以把get,post,cookie里的引号变为斜杠。magic_quotes_runtime对于进出数据库的数据可以起到格式话的作用。其实,早在以前注入很疯狂时,这个参数...

    php中$_GET与$_POST过滤sql注入的方法

    get_magic_quotes_gpc()) { if (!empty($_GET)) { $_GET = addslashes_deep($_GET); } if (!empty($_POST)) { $_POST = addslashes_deep($_POST); } $_COOKIE = addslashes_deep($_COOKIE); $

    PHP 选项及相关信息函数库

     get_magic_quotes_gpc : 取得 PHP 环境变量 magic_quotes_gpc 的值。 get_magic_quotes_runtime : 取得 PHP 环境变量 magic_quotes_runtime 的值。 getlastmod : 返回该网页的最后

    php参数过滤、数据过滤类.zip

    中开启magic_quotes_gpc和magic_quotes_runtime。magic_quotes_gpc可以把get,post,cookie里的引号变为斜杠。magic_quotes_runtime对于进出数据库的数据可以起到格式话的作用。其实,早在以前注入很疯狂时,这个参数...

    轻松实现php代码防注入,保护代码安全

    get_magic_quotes_gpc()) { return addslashes($string); } return $string; } 那么我们把以上代码放到一个公共的文件里,比如security.inc.php里面,每个文件里都include一下这个文件,那么就能够给任何一...

    PHP知识点汇总

    PHP知识点汇总 默认情况下,PHP 指令 magic_quotes_gpc 为 on,对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes...遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

    PHP 防注入函数(格式化数据)

    defined(‘MAGIC_QUOTES_GPC’) && define(‘MAGIC_QUOTES_GPC’, get_magic_quotes_gpc()); if(!MAGIC_QUOTES_GPC || $force) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = ...

    discuz的php防止sql注入函数

    复制代码 代码如下: $magic_quotes_gpc = get_magic_quotes_gpc(); @extract(daddslashes($_COOKIE)); @extract(daddslashes($_POST)); @extract(daddslashes($_GET)); if(!$magic_quotes_gpc) { $_FILES = ...

    PHP中的代码安全和SQL Injection防范3

    get_magic_quotes_gpc()) // 判断magic_quotes_gpc是否打开 { $str = addslashes($str); // 进行过滤 } $str = str_replace("_", "\_", $str); // 把 '_'过滤掉 $str = str_replace("%", "\%", $str); // 把' %...

    PHP中的代码安全和SQL Injection防范4

    get_magic_quotes_gpc()) // 判断magic_quotes_gpc是否为打开 { $post = addslashes($post); // 进行magic_quotes_gpc没有打开的情况对提交数据的过滤 } $post = str_replace("_", "\_", $post); // 把 '_'过滤...

    PHP数据的提交与过滤基本操作实例详解

    本文实例讲述了PHP数据的提交...中开启magic_quotes_gpc和magic_quotes_runtime。magic_quotes_gpc可以把get,post,cookie里的引号变为斜杠。 magic_quotes_runtime对于进出数据库的数据可以起到格式话的作用。其实,早

    比较好用的PHP防注入漏洞过滤函数代码

    PHP //PHP整站防注入程序,需要在公共文件中require_once本文件 //判断magic_quotes_gpc状态 if (@get_magic_quotes_gpc ()) { $_GET = sec ( $_GET ); $_POST = sec ( $_POST ); $_COOKIE = sec ( $_COOKIE ); $_...

    php过滤所有恶意字符(批量过滤post,get敏感数据)

    函数代码:复制代码 代码如下://php 批量过滤post,get敏感数据 if (get_magic_quotes_gpc()) { $_GET = stripslashes_array($_GET); $_POST = stripslashes_array($_POST); } function stripslashes_array(&$array) ...

Global site tag (gtag.js) - Google Analytics