background image

 

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

在 php5 的环境中我们的

$_SERVER

变量将不再受 magic_quotes_gpc 的保护,至于程序该

如何加强自己的安全性,下面我们总结了怎么保护 php 中的 cookie,get,post,files 数据哦,有
需要的朋友可参考一下
代码如下:
 
<?php 

$magic_quotes_gpc

 = get_magic_quotes_gpc(); 

@extract(daddslashes(

$_COOKIE

)); 

@extract(daddslashes(

$_POST

)); 

@extract(daddslashes(

$_GET

)); 

if

(!

$magic_quotes_gpc

) { 

$_FILES

 = daddslashes(

$_FILES

); 


 
daddslashes

 

函数

代码如下:
 

//

 

转译字符函数

function

 daddslashes(

$string

) { 

if

(!

is_array

(

$string

)) 

return

 

addslashes

(

$string

); 

foreach

(

$string

 

as

 

$key

 => 

$val

$string

[

$key

] = daddslashes(

$val

); 

return

 

$string


?>