• 注册
当前位置:1313e > 默认分类 >正文

magic_quotes_runtime(魔术引号开关)

我们可以通过以下代码来探测php环境中magic_quotes_runtime是否开启:

magic_runtime.php 源代码如下:


//当magic_quotes_runtime=On的时候,get_magic_quotes_runtime函数的返回值为1

//当magic_quotes_runtime=Off的时候,get_magic_quotes_runtime函数的返回值为0

if (get_magic_quotes_runtime())

{

echo 'magic_quotes_runtime 开启';

}

else

{

echo 'magic_quotes_runtime 未开启';

}

?>

将magic_ runtime.php 文件放在本地站点根目录之下测试,如图:

 

那么,说明:我的本地php环境,并没有开启magic_quotes_runtime,即,magic_quote_runtime=Off,或者magic_quote_runtime这个特性在我此时的php环境版本里面,也已经被php社区废除了,那么,我在编写php代码的时候,就需要将magic_quotes_runtime设置为On,或者在php代码中使用addslashes函数对外部引入的数据库资料或者文件中的特殊字符进行转义,不然,此情此景,我编写的php代码也会不安全。

其实,我的本地magic_quotes_runtime默认设置如图:

 

 

通过set_magic_quotes_runtime函数,可以修改php.ini中magic_quotes_runtime 布尔值的设置:

0:代表关闭

1:代表打开

比如,Discuz 1.0/Discuz 3.x版本中,Discuz的安装文件的开始部分代码就使用了set_magic_quotes_runtime这个函数,这样,Discuz代码就会更安全了。

Discuz 1.0安装文件部分源代码:


//-----------------------------------------------------------------------------

//    Discuz! Board 1.0 Standard - Discuz! 中文论坛 (PHP & MySQL) 1.0 标准版

//-----------------------------------------------------------------------------

//    Copyright(C) Dai Zhikang, Crossday Studio, 2002. All rights reserved

//

//    Crossday 工作室 www.crossday.com    *Discuz! 技术支持 www.Discuz.net

//-----------------------------------------------------------------------------

//  请详细阅读 Discuz! 授权协议,查看或使用 Discuz! 的任何部分意味着完全同意

//  协议中的全部条款,请举手之劳支持国内软件事业,严禁一切违反协议的侵权行为.

//-----------------------------------------------------------------------------

// Discuz! 专注于提供高效强大的论坛解决方案,如用于商业用途,您必须购买使用授权!

//-----------------------------------------------------------------------------

error_reporting(7);

set_magic_quotes_runtime(0);

define("IN_CDB", TRUE);

$action = ($HTTP_POST_VARS["action"]) ? $HTTP_POST_VARS["action"] : $HTTP_GET_VARS["action"];

$PHP_SELF = $HTTP_SERVER_VARS["PHP_SELF"];

if (function_exists("set_time_limit") == 1 && @ini_get("safe_mode") == 0) {

@set_time_limit(1000);

}

@require "./config.php";

require "./functions.php";

header("Content-Type: text/html; charset=$charset");

$version = "1.0";

Discuz 3.x安装文件部分源代码:


/**


 *      [Discuz!] (C)2001-2099 Comsenz Inc.

 *      This is NOT a freeware, use is subject to license terms

 *

 *      $Id: index.php 22348 2011-05-04 01:16:02Z monkey $

 */

error_reporting(E_ERROR | E_WARNING | E_PARSE);

@set_time_limit(1000);

@set_magic_quotes_runtime(0);

define('IN_DISCUZ', TRUE);

define('IN_COMSENZ', TRUE);

define('ROOT_PATH', dirname(__FILE__).'/../');

require ROOT_PATH.'./source/discuz_version.php';

require ROOT_PATH.'./install/include/install_var.php';

if(function_exists('mysql_connect')) {

require ROOT_PATH.'./install/include/install_mysql.php';

} else {

require ROOT_PATH.'./install/include/install_mysqli.php';

}

require ROOT_PATH.'./install/include/install_function.php';

require ROOT_PATH.'./install/include/install_lang.php';

$view_off = getgpc('view_off');

总结:

magic_quotes_gpc与magic_quotes_runtime的区别

1、 magic_quotes_runtime是对外部引入的数据库资料或者文件中的特殊字符进行转义,而magic_quotes_gpc是对post、get、cookie等数组传递过来的数据进行特殊字符转义。

2、 他们都有相应的get函数,可以对php环境中是否设置了他们相应功能特性进行探测,如:get_magic_quotes_gpc,是对magic_quotes_gpc是否设置的探测,get_magic_quotes_runtime,是对magic_quotes_runtime是否设置的探测,而且都是如果设置了,get函数返回1,如果没有设置,get函数返回0。

3、 不能在程序里面设置magic_quotes_gpc的值,原因是php中并没有set_magic_quotes_gpc这个函数,而magic_quotes_runtime有对应的能在代码中直接设置magic_quotes_runtime值的函数:set_magic_quotes_runtime,所以,magic_quotes_gpc的值,只能自己手动在php.ini文件里面设置了。

转载于:https://www.cnblogs.com/windclouds/p/5412908.html

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 162202241@qq.com 举报,一经查实,本站将立刻删除。

最新评论

欢迎您发表评论:

请登录之后再进行评论

登录