PHP MySQL character escaping problem
Background processing
$name =addslashes ($_post[' name ');//Escape single quotation mark
When insert, is it stored in the database with an escape symbol? Or remove the escape symbol?
If you're depositing the
Specific usage
addslashes prevents SQL injection
Although many domestic PHP programmers are still relying on addslashes to prevent SQL injection, it is recommended that you strengthen the Chinese to prevent SQL injection inspection. The problem
When your data has some \ "'Such a character to write to the database, and do not want to be filtered out when it is useful, will be in front of these characters automatically add \, such asChina's vast territory "haha"China is a vast country, "haha"
If the MAGIC_QUOTES_GPC in the php.ini file of your Web site is set to OFF, PHP will not precede the sensitive character with a backslash (\), because the form submission may contain sensitive characters, such as single quotes ('), which causes the
For security, we use the following function to filter some of the illegal characters passed over:
PHP Anti-injection function
The code is as follows
Copy Code
Illegal characters to filter$ArrFiltrate =array ("'", ";",
SQL injection problems in the ASP but noisy of course there are many well-known domestic and foreign PHP program "died". As for the details of the SQL injection, there are too many articles on the web, not to be introduced here.If the MAGIC_QUOTES_
mysql| Program | Data PHP code:--------------------------------------------------------------------------------
File name: filedb.php to store files in the database
/*
Example of uploading files to a MySQL database
The data table is structured as
Original: http://www.ido321.com/1252.htmlI, Htmlentities () and Htmlspecialchars ()1, Htmlentities ()1.1 function: Convert characters to HTML entities. characters include ASCII entities and ISO 8859-1 entities (HTML entity table: http://www.w3school.
PHP magic functions automatically escape magic_quotes_gpc and magic_quotes_runtim
PHP provides two magic reference functions for reference data: magic_quotes_gpc and magic_quotes_runtime. when INI is set to on, single quotation marks and double
1. The basic principles of PHP submission data filtering
1) When committing variables into the database, we must use Addslashes () to filter, like our injection problem, a addslashes () will be done. In fact, when it comes to variable values, the
Insert title here
checkusername.php file
$username = $_get[' username ');MySQL tutorial _connect (' 127.0.0.1 ', ' root ', ') or die (' could not connect: '. Mysql_error ());mysql_select_db (' Test ');When stitching SQL statements, you
Anti-injection in PHP generally write a global file to filter special strings, this article summarizes a variety of PHP anti-injection function code, but also anti-SQL injection can be consulted.
For security, we used the following function to
NL2BR (); N to
Addslashes (); Strips tutorial Lashes (); Escape special characters when working with database tutorialsDefinition: the Addslashes () function adds a backslash before the specified predefined character.Syntax: Addslashes (String)Note:
Article Which is incorrect or ambiguous ~~~
Configurations and functions related to PhP string escaping are as follows:1. magic_quotes_runtime2. magic_quotes_gpc3. addslashes () and stripslashes ()4. mysql_escape_string ()5. addcslashes () and
The SQLinjection problem is very popular in asp. of course, there are still many well-known php programs at home and abroad "killed ". As for SQLinjection details, there are too many articles on the Internet, so we will not introduce them here. If
When your data has some " 'Such characters to write to the database inside, and want to not be filtered out, it is very useful, will be in these words match either automatically added, such asChina's vast territory "haha"China's vast territory
PHP character escape Function Summary. sometimes, for the sake of security, we need to escape the character strings entered by the user, which may be incorrect or obscure ~~~
Configurations and functions related to PHP string escaping are as
Three functions that I often confuse in PHP, and three functions obfuscated in PHP. Three functions that I often confuse in PHP: www.ido321.com1252.html 1. htmlentities () and htmlspecialchars () 1. htmlentities () 1.1: three functions that I often
The GET_MAGIC_QUOTES_GPC function is a method used to determine if the data provided by the user is added to the slash, which in the php.ini configuration file Oh, this article will describe the GET_MAGIC_QUOTES_GPC () function description. Let's
The difference between single quotes and double quotes in php is very important in programming languages, both single quotes and double quotes. PHP quotes are easier to use than ASP quotes. in ASP, to substitute data into a variable, you must use
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.