It is enough to filter the htmlspecialchars variables delivered by get.

Source: Internet
Author: User
Is htmlspecialchars enough to filter the variables submitted by get? For example, to implement the user name search function, the user name is actually get. Is it safe to use htmlspecialchars? PHPcodehtmlspecialchars (trim ($ _ GET [username]), ENT_QUOTES); ------ solution ------------------ is it enough to filter the variable htmlspecialchars submitted by get?
For example, to implement the user name search function, the user name is actually get. Is it safe to use htmlspecialchars?
PHP code
  htmlspecialchars(trim($_GET['username']), ENT_QUOTES);


------ Solution --------------------
Addslashes processing ('), ("), (\), and NULL
------ Solution --------------------
In fact, you want to prevent SQL injection. For <php5.4.0, when get_magic_quotes_gpc () is enabled, the data submitted by get/post/cookie is automatically escaped. However, if get_magic_quotes_gpc () is removed from php5.4.0, false is always returned.

Therefore, the safest thing is to escape through mysql_real_escape_string () to prevent attacks to the database. it is safe to write the following code:

If (get_magic_quotes_gpc ()){
$ Username = stripslashes ($ _ GET ['username']);
}
Else {
$ Username = $ _ GET ['username'];
}

$ Username = mysql_real_escape_string ($ username );
...................................

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.