PHP

[PHP] auto_prepend_file, auto_append_file

qjadud22 2019. 1. 28. 12:30


1. auto_prepend_file, auto_append_file 이란? 




- php.ini or httpd.conf 설정을 통해 소스 내에 추가 없이 스크립트 실행 전, 후 로 php 파일을 require 할 수 있다. 


1) auto_prepend_file 이란? 

- php 파일 실행 전에 지정된 auto_prepend_file 부터 실행 된다. 


2) auto_append_file 이란? 

- php 파일 실행 후에 지정된 auto_append_file이 실행 된다. 


auto_prepend_file은 점검 페이지 및 validation 처리 등 사전 작업이 필요한 경우 유용하게 사용이 가능하다.




2. 사용법 



php.ini or httpd.conf 설정 방법에 대해 알아보겠다. 


1) php.ini 설정 


- sudo vi /etc/php.ini 



auto_prepend_file 또는 auto_append_file에 원하는 경로 입력 


2) http.conf 


- sudo vi /etc/httpd/conf/httpd.conf 



위에 대해 설명하면 /home/service/www/test 디렉토리에 접근시 /home/service/www/auto_prepend_file.inc 파일이 먼저 실행 된다.

 (VirtualHost로도 설정이 가능) 



설정 이후 apache 재시작 

service httpd restart