Home >Backend Development >PHP Tutorial >How to use PHP get_magic_quotes_gpc and addslashes

How to use PHP get_magic_quotes_gpc and addslashes

WBOY
WBOYOriginal
2016-07-25 09:13:341421browse
This judgment condition is often encountered in the code
  1. if(!get_magic_quotes_gpc())
  2. {
  3. $p=addslashes($name);//$name is a value to obtain user input
  4. }
Copy code
First look at get_magic_quotes_gpc() The function of this function is:
magic_quotes_gpc sets whether to automatically add a backslash (and escape) before '(single quote)" (double quote) (backslash) in the data transmitted from GPC (get, post, cookie)
get_magic_quotes_gpc() checks whether this item is set. If it is set, it returns true. If it is not set, it returns false
If it is not set, we need to manually escape some special characters, such as ',", these three mentioned above.
If you manually escape special characters? Use the addslashes('content') method. The parameter is the string that needs to be escaped.

So the above code is to first check whether the system automatically adds a backslash before special characters. If not, we need to call the method addslashes() to escape the special characters in the content entered by the user.
php technical issuesWelcome to join the group to discuss: 256271784, verification code: cxy, if you don’t write it, the verification will not be passed.



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