PHP - Need Help Declaring And Using a Constant -


i'm new php. i've been looking @ documentation , having problem. have multi-page php site working on. having problem relative paths (php relative path issues) , pointed following url(php include relative path). want use similar following code snippet in post:

if (is_production()) {     define('root_path', '/some/production/path'); } else {     define('root_path', '/root'); } include root_path . '/connect.php'; 

on page add define statement (index.php?) , how can reference root_path on every subsequent page has include statement?

i tried adding define statement index.php page calling root_path on other page results in: use of undefined constant root_path

index.php: define('root_path', '/some/production/path');
other page: include_once(root_path."/library/api/database.inc.php");

you have 2 possible (common) approaches:

create files each environment production.inc.php , development.inc.php , include 1 need in index.php using is_production() condition.

-- or --

create single file contains

if (is_production()) {     define('root_path', '/some/production/path'); } else {     define('root_path', '/root'); } 

and include single file pages need constants.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -