search
Homephp教程php手册php中addslashes函数与sql防注入,addslashessql

php中addslashes函数与sql防注入,addslashessql

本文实例讲述了php中addslashes函数与sql防注入。分享给大家供大家参考。具体分析如下:

addslashes可会自动给单引号,双引号增加\\\\\\,这样我们就可以安全的把数据存入数据库中而不黑客利用,参数'a..z'界定所有大小写字母均被转义,代码如下:

复制代码 代码如下:

echo addcslashes('foo[ ]','a..z'); //输出:foo[ ]
$str="is your name o'reilly?"; //定义字符串,其中包括需要转义的字符
echo addslashes($str);  //输出经过转义的字符串


定义和用法:addslashes() 函数在指定的预定义字符前添加反斜杠.

这些预定义字符是:单引号 ('),双引号 ("),反斜杠 (),null

语法:addslashes(string),当然这个函数更安全,实例代码如下:

复制代码 代码如下:

$str="test"; //定义包含特殊字符的字符串
$new=htmlspecialchars($str,ent_quotes);  //进行转换操作
echo $new;           //输出转换结果
//不过输出时要用到
$str="jane & 'tarzan'";  //定义html字符串
echo html_entity_decode($str);   //输出转换后的内容
echo "
";
echo html_entity_decode($str,ent_quotes); //有可选参数输出的内容

希望本文所述对大家的PHP程序设计有所帮助。

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot 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.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment