if(!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 > 자유게시판

자유게시판

if(!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 정보

if(!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

본문

 
1, define("_GNUBOARD_", TRUE);
2, define("_GNUBOARD_", FALSE);
3, 선언x
 
문제1:
선언하지 않은 것도 !defined 에 속하고...
 
문제2:
if(!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
define 된 상수는 문자형으로 "상수" 처리하는것이 맞는지.
 
문제3:
false 라고 선언되어도 통과 된다면
false 또한 config.php를 거쳤다는 증거로 보아도 무방하다는 것일때  
0 과 1로 리턴되는 불린값을 염두에 두고
true,false 를 선택하신듯 한데... 성공시만 1 을 리턴하고 아니면 공백입니다. 
공백값을  
!defined 로 확인할때 false 는 무의미 해서 2번과 같은 결과가 될듯... 
  
//확인
echo _GNUBOARD_ ; 
 
아무리 생각해도 요고 같네요.
if(_GNUBOARD_ !=1) exit; // 개별 페이지 접근 불가
 
정리가 안되지만..
암튼 요런 생각을...해봤습니다. ^^;
무의식적으로 쓰고는 있지만..
추천
0
  • 복사

댓글 4개

http://www.php.net/manual/kr/language.constants.php#language.constants.syntax


Re: Storm.
I ran that code (in PHP4)

<?php
if (DEBUG) {
  // echo some sensitive data.
}
?>



and saw this warning:
"Use of undefined constant DEBUG - assumed 'DEBUG'"
A clearer workaround is to use
<?php
if (defined('DEBUG')) {
  // echo some sensitive data.
}
?>
Thanks for pointing out this big gotcha.
Another reason to turn on warnings during testing.  Good web servers are set up to suppress warning and error output to the browser, so this is handy:


<?php
if (defined('DEBUG')) {
  error_reporting(E_ALL);
  set_error_handler('debug_ErrorHandler');
}
function debug_ErrorHandler($errno, $errstr, $errfile, $errline) {
  print("PHP Error [$errno] [$errstr] at $errline in $errfile.<br>");
}
?>


hafenator2000 at yahoo dot com
21-Apr-2005 02:09
PHP Modules also define constants.  Make sure to avoid constant name collisions.  There are two ways to do this that I can think of.
First: in your code make sure that the constant name is not already used.  ex. <?php if (! defined("CONSTANT_NAME")) { Define("CONSTANT_NAME","Some Value"); } ?>  This can get messy when you start thinking about collision handling, and the implications of this.
Second: Use some off prepend to all your constant names without exception  ex. <?php Define("SITE_CONSTANT_NAME","Some Value"); ?>

Perhaps the developers or documentation maintainers could recommend a good prepend and ask module writers to avoid that prepend in modules.
storm
18-Apr-2005 09:54
An undefined constant evaluates as true when not used correctly. Say for example you had something like this:

settings.php
<?php
// Debug mode
define('DEBUG',false);
?>

test.php
<?php
include('settings.php');

if (DEBUG) {
  // echo some sensitive data.
}
?>

If for some reason settings.php doesn't get included and the DEBUG constant is not set, PHP will STILL print the sensitive data. The solution is to evaluate it. Like so:

settings.php
<?php
// Debug mode
define('DEBUG',0);
?>

test.php
<?php
include('settings.php');

if (DEBUG == 1) {
  // echo some sensitive data.
}
?>

Now it works correctly.
© SIRSOFT
현재 페이지 제일 처음으로