Jump to content

Constants are not defined??


Nethox

Recommended Posts

Hi,

 

I have a small CMS I coded and developped on my local WAMP server and everything worked fine but when I decided to export everything to my hostgator server I realized that the constants I define in some of my includes are not being defined..

 

Here is one of the errors I get :

Fatal error: require_once() [function.require]: Failed opening required 'LIB_PATHDSdatabase.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/nethox/public_html/photo_gallery/includes/photograph.php on line 2

 

You can see that LIB_PATH is not defined and even the .DS. is not working..

 

Here is a sample of the code I made :

 

<?php
// Defining core paths
// Defining them as absolute paths to make sure that require_once works as expected

// DIRECTORY_SEPARATOR is a PHP pre-defined constant
// (will do \ for Windows, / for Unix) 
defined('DS') ? null : define('DS', '/');

defined('SITE_ROOT') ? null : define('SITE_ROOT', 'http://www.lemontree-designs.com'.DS.'photo_gallery');

defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.'/includes');

defined('LOG_PATH') ? null : define('LOG_PATH', SITE_ROOT.DS.'logs');

defined('PUBLIC_AREA') ? null : define('PUBLIC_AREA', 'http://www.lemontree-designs.com'.DS.'photo_gallery'.DS.'public');

// Load config file first
require_once(LIB_PATH."/config.php");

// Load basic functions next so that everything after can use them
require_once(LIB_PATH.DS."functions.php");

// Load core objects
require_once(LIB_PATH.DS."session.php");
require_once(LIB_PATH.DS."database.php");
require_once(LIB_PATH.DS."pagination.php");
// Load database-related classes
require_once(LIB_PATH.DS."user.php");
require_once(LIB_PATH.DS."photograph.php");
require_once(LIB_PATH.DS."comment.php");

?>

 

Any help is appreciated!

 

EDIT : For the sake of debugging, I've changed the defined value of DS to '/' instead of DIRECTORY_SEPARATOR to see if it's what caused an issue..

Link to comment
https://forums.phpfreaks.com/topic/247924-constants-are-not-defined/
Share on other sites

Don't include PHP files via an HTTP path. Use either the absolute or relative path on the filesystem. From the looks of it LIB_PATH is in the root folder so therefore a path like this should suffice.

defined('LIB_PATH') ? null : define('LIB_PATH', DIRECTORY_SEPARATOR . 'includes');
Placing the directory separator before the path indicates that the path is relative to the root directory.

Also PHP has a constant called DIRECTORY_SEPARATOR which should be of use to you.

The problem is occurring in photograph.php -

 

in /home/nethox/public_html/photo_gallery/includes/photograph.php on line 2

 

You are using a URL to include files. That is creating two problems. 1) Only the output from the file is being included/required, the same as if you browsed to the file, and 2) anything you define in the main file's scope, like defined constants, don't exist in the included/required file because it is being parsed and executed in a completely separate http request/process.

 

You should be including/requiring files using a file system path, not a URL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.