php daddslashes()和 saddslashes()有哪些区别分析
//GPC过滤,自动转义$_GET,$_POST,$_COOKIE中的特殊字符,防止SQL注入攻击
$_GET = saddslashes($_GET);
$_POST = saddslashes($_POST);
复制代码 代码如下:
下面是daddslashes()和 saddslashes()的例子eg: saddslashes function daddslashes($string, $force = 0, $strip = FALSE) {
//字符串或数组 是否强制 是否去除
//如果魔术引用未开启 或 $force不为0
if(!MAGIC_QUOTES_GPC || $force) {
if(is_array($string)) { //如果其为一个数组则循环执行此函数
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
//如果魔术引用开启或$force为0
//下面是一个三元操作符,如果$strip为true则执行stripslashes去掉反斜线字符,再执行addslashes
//$strip为true的,也就是先去掉反斜线字符再进行转义的为$_GET,$_POST,$_COOKIE和$_REQUEST $_REQUEST数组包含了前三个数组的值
//这里为什么要将$string先去掉反斜线再进行转义呢,因为有的时候$string有可能有两个反斜线,stripslashes是将多余的反斜线过滤掉
$string = addslashes($strip ? stripslashes($string) : $string);
}
}
return $string;
}eg: saddslashes function saddslashes($string) { if(!MAGIC_QUOTES_GPC){
if(is_array($string)) { //如果转义的是数组则对数组中的value进行递归转义
foreach($string as $key => $val) {
$string[$key] = saddslashes($val);
}
} else {
$string = addslashes($string); //对单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符),进行转义
}
return $string;
}else{
return $string;
}
主要就是:
saddslashes可以实现对每一个数据进行转义处理了
复制代码 代码如下:
function saddslashes($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = saddslashes($val);
}
} else {
$string = addslashes($string);
}
return $string;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.