Home >Backend Development >PHP Tutorial >Usage examples of set_magic_quotes_runtime() and get_magic_quotes_gpc()

Usage examples of set_magic_quotes_runtime() and get_magic_quotes_gpc()

WBOY
WBOYOriginal
2016-07-25 08:56:411025browse
P & lt; p & gt; & lt ;? Php
echo get_magic_quotes_gpc (); // detect, output 0
echo & lt;/p & gt;
    & lt; tiny_marker & gt;/p & gt;
  1. & lt; p & gt; post [' name']; // jason'name
  2. echo addslashes(

  3. tiny_mce_marker

  4. POST['name']); // jason'name

  5. if (!get_magic_quotes_gpc()) {
  6. $name = addslashes(

  7. tiny_mce_marker

  8. POST['name']);

  9. } else {
  10. $name =

  11. tiny_mce_marker

  12. POST['name'];

  13. }

  14. echo $name; //jason'name
  15. //Safely written to the database
  16. ?>

  17. Copy code
In the following example, both functions are processed.

if(version_compare(PHP_VERSION,'6.0.0','<') ) {
@set_magic_quotes_runtime (0);
    define('MAGIC_QUOTES_GPC',get_magic_quotes_gpc()?True: False);
  1. }
  2. Copy code
In addition, you can also use ini_get and ini_set to read and set the system configuration:

!ini_get('magic_quotes_runtime') && ini_set('magic_quotes_runtime', 0); //Auto-escape function is off
    Copy code
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