Jump to content

include constantsdatafile.inc.php from any directory


wobuck

Recommended Posts

I am trying to include a inc.php file within a normal .php file from a single directory as I am using it in several directories but cannot get it to work and have tried many different techniques.

 

Any ideas on the coding that would work would be appreciated?

 

Alternatively, I would be happy to set the constants in a mysql db but am unsure how I would unpack/read it so as to get it in the php program as code i.e.

 

mysql db

field 1  field 2

name    $name

 

Program

<?php

$name;

?>

Your Question

"What's wrong with include('inc.php'); ?"

 

include("constantsdata.inc.php"); 

this works ok but the file,constantsdata.inc.php, has to be in the same directory as the php file calling the include which means I have to maintain every copy of this file in all directories I am using it.

 

I have tried variants like:

 

include("http://localhost/folder/constantsdata.inc.php");

include('http://localhost/folder/constantsdata.inc.php');

 

to call the file from another directory e.g. folder but it does not work?

Using BlueSkyIS's response set me on the right 'path' to resolving the issue:

 

Used this to find paths:

print realpath(basename(getenv("SCRIPT_NAME")));

print("<br>");

print realpath(basename(getenv("DOCUMENT ROOT")));

print("<br>");

 

Resulting in working out this code which works:

$docRoot = getenv("DOCUMENT_ROOT");

include $docRoot."/folder/constantsdata.inc.php";

 

Many Thanks to BlueSkyis!

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.