Jump to content


Photo

Quick/Simple PHP logic question/"problem" -->*SOLVED*<--


  • Please log in to reply
2 replies to this topic

#1 Lyricsride

Lyricsride
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationQuebec

Posted 06 August 2006 - 02:52 AM

heya folks. An issue here regarding includes. I'm implementing include-security which i have basically done successfully i believe. But there is something i do not understand. Here are my three versions of the code:



First Version That Doesn't Work

config.php
--------------------------
<?php

//security measure
if (
//a matching constant must be defined [above] in a script that calls this include
!defined('include_constant','I Exist')
)
//otherwise the include will die, assuming someone is trying to directly access this include file
die("ERROR:Why are you trying to access a restricted include file! Please stop, thank-you. =]");

$vpv4_host = "localhost";
$vpv4_db = "vpv4" ;
$vpv4_usr = "root" ;
$vpv4_pw = "314314" ;
$vpv4_connect = mysql_pconnect($vpv4_host,
$vpv4_usr,
$vpv4_pw) or trigger_error(mysql_error(),E_USER_ERROR);
?>
--------------------------

index.php
--------------------------
<?php

//needed constant for include permissions
define('include_constant','I Exist');
require_once($_SERVER['DOCUMENT_ROOT'].'/vpv4/includes/config.php');

?>


Hello World!
--------------------------

RESULTING ERROR: "Warning: Wrong parameter count for defined() in c:\server\Apache2.2\htdocs\vpv4\includes\config.php on line 6
ERROR:Why are you trying to access a restricted include file! Please stop, thank-you. =]
"











Second Version That Doesn't Work

config.php
--------------------------
<?php

//security measure
if (
//a matching constant must be defined [above] in a script that calls this include
!defined('include_constant')
)
//otherwise the include will die, assuming someone is trying to directly access this include file
die("ERROR:Why are you trying to access a restricted include file! Please stop, thank-you. =]");

$vpv4_host = "localhost";
$vpv4_db = "vpv4" ;
$vpv4_usr = "root" ;
$vpv4_pw = "314314" ;
$vpv4_connect = mysql_pconnect($vpv4_host,
$vpv4_usr,
$vpv4_pw) or trigger_error(mysql_error(),E_USER_ERROR);
?>
--------------------------

index.php
--------------------------
<?php

//needed constant for include permissions
define('include_constant');
require_once($_SERVER['DOCUMENT_ROOT'].'/vpv4/includes/config.php');

?>


Hello World!
--------------------------

RESULTING ERROR: "Warning: Wrong parameter count for define() in c:\server\Apache2.2\htdocs\vpv4\index.php on line 4
ERROR:Why are you trying to access a restricted include file! Please stop, thank-you. =]
"













First Version That Does Work

config.php
--------------------------
<?php

//security measure
if (
//a matching constant must be defined [above] in a script that calls this include
!defined('include_constant')
)
//otherwise the include will die, assuming someone is trying to directly access this include file
die("ERROR:Why are you trying to access a restricted include file! Please stop, thank-you. =]");

$vpv4_host = "localhost";
$vpv4_db = "vpv4" ;
$vpv4_usr = "root" ;
$vpv4_pw = "314314" ;
$vpv4_connect = mysql_pconnect($vpv4_host,
$vpv4_usr,
$vpv4_pw) or trigger_error(mysql_error(),E_USER_ERROR);
?>
--------------------------

index.php
--------------------------
<?php

//needed constant for include permissions
define('include_constant','I Exist');
require_once($_SERVER['DOCUMENT_ROOT'].'/vpv4/includes/config.php');

?>


Hello World!
--------------------------

RESULTING SUCCESS: "Hello World!"



This confuses me. It seems logically that the second version should work becasue it has all constant arguments defined? The third works yet it doesn't [have all arguments defined] while the first doesn't work yet it's similar to the third. What is PHP thinking here? I feel it's important for me to know... =)

Anyway i could improve this by the way? Thanks!
Lyricsride

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 06 August 2006 - 09:41 AM

The first one does not work because the defined () needs one parm only
PHP manual: bool defined ( string name )

The second one does not work because the define needs at least 2 parms
PHP manual: bool define ( string name, mixed value [, bool case_insensitive] )

The third one is syntactially correct



RTFM is an almost extinct art form, it should be subsidized.

#3 Lyricsride

Lyricsride
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationQuebec

Posted 06 August 2006 - 11:48 PM

Thanks ronverdonk. When you say "needs one param only" i assume you mean also "will only take one"!  8) Thanks for clearing that up, although i find it a little illogical personally, i'm not going to argue with the code!

Thanks a lot bud, cheers.
Lyricsride




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users