Differences between htmlspecialchars and addslashes and et_magic_quotes_gpc

Source: Internet
Author: User
Differences between htmlspecialchars and addslashes and et_magic_quotes_gpc htmlspecialchars and
Addslashes and
Et_magic_quotes_gpc

There seems to be no difference between these three things. I don't know how to deal with the relationship between them.


Reply to discussion (solution)

Htmlspecialchars converts html objects to html objects, and occasionally converts html objects to object storage before they are stored in the database (generally rich text editing content)
Addslashes escapes special characters. generally, special characters are escaped during database query to prevent SQL injection.
Get_magic_quotes_gpc: determines whether magic_quotes_gpc is enabled (if enabled, php will automatically run addslashes on GET, POST, and COOKIE data) to prevent your second escape

The htmlspecialchars () function converts some predefined characters into HTML objects.
The predefined characters are:
& (And number) become &
"(Double quotation marks)"
'(Single quotes)'
<(Less than) becomes <
> (Greater than) become>

The addslashes () function adds a backslash before the specified predefined character.
By default, the magic_quotes_gpc command of PHP is on, and addslashes () is automatically run for all GET, POST, and COOKIE data (). Do not use addslashes () for strings that have been escaped by magic_quotes_gpc, because this causes double-layer escape. In this case, you can use the get_magic_quotes_gpc () function for detection.

Et_magic_quotes_gpc, which should be
Get_magic_quotes_gpc ():
View magic_quotes_gpc value. 0 = Close. 1 = open

Htmlspecialchars has nothing to do with the last two methods.

If get_magic_quotes_gpc is 1, it indicates that the data in GET/POST has been executed by addslashes.
If it is 0, it indicates that addslashes has not been executed, and the user needs to execute addslashes to escape

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.