PHP 간단한 팁들
인코딩, 디코딩 함수
-
사용법
customEncrypt('encrypt', 'String'); customEncrypt('decrypt', 'String');
-
PHP 암호화
function customEncrypt($action, $string) { $output = false; $encrypt_method = "AES-256-CBC"; $secret_key = 'This is my secret key'; $secret_iv = 'This is my secret iv'; // hash $key = hash('sha256', $secret_key); // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning $iv = substr(hash('sha256', $secret_iv), 0, 16); if( $action == 'encrypt' ) { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if( $action == 'decrypt' ){ $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; }
에러출력
-
에러출력(모든 에러 출력)
error_reporting(E_ALL); ini_set("display_errors", 1);
-
에러출력 감추기
error_reporting(0); ini_set("display_errors", 0);
-
기타
// 공지(NOTICE)를 제외하고 출력할 경우 error_reporting(E_ALL & ~E_NOTICE);
쿠키
- 같은 도메인끼리 쿠키 공유
define('ADMIN_COOKIE_PATH', '/'); define('COOKIE_DOMAIN', '.[.도메인]'); // 도메인 앞에 ‘.’(점)을 붙여야 됨(.domain.com 형태) define('COOKIEPATH', '/'); define('COOKIEHASH', md5([도메인]')); // 도메인 앞에 ‘.’(점)이 없어야 됨(domain.com 형태)