magic 에 대하 여quotes_gpc

33111 단어 c
원본:
http://www.phpfans.net/bbs/viewthread.php?tid=6860&page=1&extra=page%3D1
Magic Quotes
[클립보드 로 복사]
CODE: Magic Quotes is a process that automagically escapes incoming data to the PHP script. Its preferred to code with magic quotes off and to instead escape the data at runtime, as needed. 

What are Magic Quotes
[클립보드 로 복사]
CODE: When on, all  (single-quote), " (double quote), \ (backslash) and NULL characters are escaped with a backslash automatically. This is identical to what addslashes() does.    
  
There are three magic quote directives: ;


magic_quotes_gpc
[클립보드 로 복사]
CODE: Affects HTTP Request data (GET, POST, and COOKIE). Cannot be set at runtime, and defaults to on in PHP. 

magic_quotes_runtime
[클립보드 로 복사]
CODE: If enabled, most functions that return data from an external source, including databases and text files, will have quotes escaped with a backslash. Can be set at runtime, and defaults to off in PHP. 

magic_quotes_sybase
[클립보드 로 복사]
CODE: If enabled, a single-quote is escaped with a single-quote instead of a backslash. If on, it completely overrides magic_quotes_gpc. Having both directives enabled means only single quotes are escaped as ''. Double quotes, backslashes and NULLs will remain untouched and unescaped. 

Why use Magic Quotes 1 Useful for beginners          Magic quotes are implemented in PHP to help code written by beginners from being dangerous. Although SQL Injection is still possible with magic quotes on, the risk is reduced.          2Convenience          For inserting data into a database, magic quotes essentially runs addslashes() on all Get, Post, and Cookie data, and does so automagically.          Why not to use Magic Quotes 1 Portability
[클립보드 로 복사]
CODE: Assuming it to be on, or off, affects portability. Use get_magic_quotes_gpc() to check for this, and code accordingly. 

2 Performance
[클립보드 로 복사]
CODE: Because not every piece of escaped data is inserted into a database, there is a performance loss for escaping all this data. Simply calling on the escaping functions (like addslashes()) at runtime is more efficient.     
   
Although php.ini-dist enables these directives by default, php.ini-recommended disables it. This recommendation is mainly due to performance reasons. 

3 Inconvenience
[클립보드 로 복사]
CODE: Because not all data needs escaping, it's often annoying to see escaped data where it shouldn't be. For example, emailing from a form, and seeing a bunch of  within the email. To fix, this may require excessive use of stripslashes(). 

이 영어 들 은 정말 나 같은 사람 에 게 충분 한 인내심 이 필요 하 다.(내 가 인내심 이 있다 는 것 이 아니 라 내 가 영 어 를 못 한다 고 말 하 는 것 이다)아까 도 말 했 듯 이 일반인 에 게 는 앞의 두 단락 만 보면 된다.특히 내 가 빨간색 으로 표시 한 글자!!또한,특히 마술 인용 발생 작용 은$를 전달 하 는 것 입 니 다.GET,$_POST,$_쿠키 때 다음 사례.
[클립보드 로 복사]
CODE: 1. 
: magic_quotes_gpc
=off 
。 。 

: 
 $data="snow''''sun" ; (snow sun ). 

:  :"snow''''sun"  , 

:  sql ,mysql sql , 。 

: 。 

: 。 

:  sql 。 


[클립보드 로 복사]
CODE: 2. 
: magic_quotes_gpc
=off 
addlashes
() 。 。 

: 
 $data="snow''''sun" ; (snow sun ). 

:  :"snow''''sun"  , 

: sql ,  

:snow
''''sun ( ) 

:snow''''sun ( ) 

: addslashes() ' sql , 
\' , snow'''
sun  snowsun 

[클립보드 로 복사]
CODE: 3. 
: magic_quotes_gpc
=on 
。 。 

: 
 $data="snow''''sun" ; (snow sun ). 

:  :"snow''''sun"  , 

: sql ,  

:snow
''''sun ( ) 

:snow''''sun ( ) 

: magic_quotes_gpc=on  ' sql , 
\' , snow'''
sun snowsun。 

[클립보드 로 복사]
CODE: 4. 
: magic_quotes_gpc
=on 
addlashes
() 。 。 

: 
 $data="snow''''sun" ; (snow sun ). 

:  :"snow''''sun"  , 

: sql ,  

:snowsun 
( ) 

:snowsun ( ) 

: magic_quotes_gpc=on  sql , 
addslashes
,  
, snowsun 


총 결 은 다음 과 같다.  1.매 직quotes_gpc=on 의 경우,  데이터베이스 에 입력 하고 출력 하 는 문자열 데 이 터 를 만 들 지 않 아 도 됩 니 다.  addslashes()와 stripslashes()의 조작 으로 데이터 도 정상적으로 표 시 됩 니 다.  만약 이때 입력 한 데 이 터 를 addslashes()로 처리 했다 면,  그러면 출력 할 때 stripslashes()를 사용 하여 불필요 한 역 슬 래 쉬 를 제거 해 야 합 니 다.  2.매 직quotes_gpc=off 의 경우  입력 데 이 터 를 addslashes()로 처리 해 야 하지만,stripslashes()포맷 출력 을 사용 할 필 요 는 없습니다.  addslashes()는 역 슬 래 쉬 와 함께 데이터 베 이 스 를 기록 하지 않 았 기 때문에 my sql 문 구 를 실행 하 는 데 도움 을 주 었 습 니 다.매 직quotes_gpc 역할 범 위 는:WEB 클 라 이언 트 서버;작용 시간:요청 시작 시,예 를 들 어 스 크 립 트 가 실 행 될 때.magicquotes_runtime 역할 범위:파일 에서 읽 은 데이터 나 exec()를 실행 한 결과 또는 SQL 조회 에서 얻 은 것;작용 시간:스 크 립 트 가 실행 상태 에 접근 할 때마다 발생 하 는 데이터

좋은 웹페이지 즐겨찾기