get_magic_quotes_gpc()

Language/PHP 2010. 4. 7. 13:56

get_magic_quotes_gpc()

(PHP 3>= 3.0.6, PHP 4 , PHP 5)

get_magic_quotes_gpc --  Gets the current configuration setting of magic quotes gpc

설명
int get_magic_quotes_gpc ( void )

Returns the current configuration setting of magic_quotes_gpc (0 for off, 1 for on).

참고: If the directive magic_quotes_sybase is ON it will completely override magic_quotes_gpc. So even when get_magic_quotes() returns TRUE neither double quotes, backslashes or NUL's will be escaped. Only single quotes will be escaped. In this case they'll look like: ''

Keep in mind that the setting magic_quotes_gpc will not work at runtime


보통 Query문을 만들기 전에 addslash()를 써서 I'm boy 를 I\'m boy 와 같은 형태로 이스케이프 시키게 되는데.... php.ini 설정에 magic_quotes 설정이 On되어 있는 경우 Get, Post, Cookie가 전달시에 자동으로 이스케이프를 하므로 addslash()를 하면 중복 이스케이프하게 된다. 그래서 magic_quotes 설정이 On되어 있는지 확인하는 것이 바로 get_magic_quotes_gpc() 함수임


이 함수를 Tettertools에서는 아래와 같이 활용함

테터툴즈에서 사용하는 방법 (Language : php)
if (get_magic_quotes_gpc()) {
  foreach ($_GET as $key => $value)
       $_GET[$key] = stripslashes($value);
  foreach ($_POST as $key => $value)
       $_POST[$key] = stripslashes($value);
  foreach ($_COOKIE as $key => $value)
       $_COOKIE[$key] = stripslashes($value);
}

php.net 에서는 다음과 같은 예시가 있음. 보니깐 재귀용법을 사용했음

phpschool에 올라온거 (Language : php)
<?php
if (get_magic_quotes_gpc()) {
  function stripslashes_deep($value)
  {
       $value = is_array($value) ?
                   array_map('stripslashes_deep', $value) :
                   stripslashes($value);

       return $value;
  }

  $_POST = array_map('stripslashes_deep', $_POST);
  $_GET = array_map('stripslashes_deep', $_GET);
  $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
 

모두 같은 동작을 하지만 해석하기는 테터가 더 쉬움.


출처 - 지돌스타(http://blog.jidolstar.com/127)

'Language > PHP' 카테고리의 다른 글

date() 함수 포맷  (0) 2010.04.30
@의 역할  (0) 2010.04.27
php 배열  (0) 2010.04.27
PHP - $_SERVER 함수  (1) 2010.04.22
PHP 함수  (0) 2010.04.06
: