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;

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.