Reputation: 1520
I tried to define constants in my config.php file. Its primary use is just configuration, as I'm sure you guessed. But it isn't working. here's my config.php file:
<?php
define("KPEREQUEST", "0", true);
define("KPERESPONSE", "1", true);
define("KPEGET", 0, true);
define("KPEPOST", 1, true);
?>
and here's the result when I include config.php and print the define kPAPost:
KPEPOST: ""
but here's the result if i define the constants in index.php AND i print them from index.php:
KPEPOST: "1"
** EDIT **
heres my index.php file:
<?php
$title = "API Documents";
include 'header.php';
include "config.inc.php";
echo "KPEPOST: \"" . KPEPOST . "\"";
?>
<?php include 'footer.php'; ?>
I've seen this done a million times in wordpress, magento, etc. I have no idea why this isn't working and I've done a ton of research to figure it out but I'm at a dead end now. Any help would be appreciated. Why can't I define a constant in a config file and use the define in files that include the config file?
Upvotes: 2
Views: 704
Reputation: 1520
another possible solution is to use ./ in front of the filename during the include. i discovered it inadvertently.
define("kPEPost", "1");
and the include:
include("./header");
include("./includes/config.inc.php");
Upvotes: 0
Reputation: 121809
It sounds like you just don't have config.php (or that particular copy of config.php) in your include path.
Do this:
define('BASE_DIR', realpath(__FILE__));
Then you can do this:
require_once BASE_DIR.'config.php';
Upvotes: 1