search
Homephp教程php手册php daddslashes()和 saddslashes()有哪些区别分析

php daddslashes()和 saddslashes()有哪些区别分析

Jun 13, 2016 am 11:56 AM
getphpanalyzethe differenceandWhichhaveautomaticescapefilter

//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;
}

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

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

Dreamweaver CS6

Visual web development tools

MantisBT

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.