PHP prevents single quotes, double quotes in accept page escape

Source: Internet
Author: User

In the PHP page, if you don't want the following to happen:

Single quotes are escaped to \ '

Double quotes are escaped to \ "

Then you can set the following to prevent:

Method One: Set in php.ini: MAGIC_QUOTES_GPC = Off


Method Two: $str =stripcslashes ($STR)

Add

1. In the case of PHP magic_quotes_gpc=on,

Example

The code is as follows Copy Code

<?php

$str =$_post[' str '];

if (!GET_MAGIC_QUOTES_GPC ()) {//First judgment not open

$newStr =addslashes ($STR);//Then filter with addslashes function

}

?>

We can not make string data for input and output databases
Addslashes () and Stripslashes (), the data is also displayed correctly.

If you addslashes () the input data at this time,
Then you must use Stripslashes () in the output to remove the extra backslash.

2. For PHP Magic_quotes_gpc=off

You must use Addslashes () to process the input data, but you do not need to use stripslashes () to format the output
Because Addslashes () did not write the backslash to the database, it only helped MySQL complete the execution of the SQL statement

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.