Forum Moderators: coopster

Message Too Old, No Replies

how can I make a constant available to some scripts w/o include()?

         

ocelot

7:18 am on Nov 25, 2004 (gmt 0)

10+ Year Member



I want a constant (variable that don't need to change) to be available to some scripts.

but the constant I'm talking about is a base url that should be available to scripts deep in a directory structure. so I can't use include()

so how can I make that constant just always there whenever a script uses it?

jatar_k

7:21 am on Nov 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> available to scripts deep in a directory structure. so I can't use include()

why not? you can use include from anywhere. just use the explicit path from the server root

dcrombie

3:49 pm on Nov 25, 2004 (gmt 0)



jatar_k is right - but if there IS something preventing you from using "include" you can also prepend a file using .htaccess:

php_value auto_prepend /path/to/file

ocelot

10:42 pm on Nov 25, 2004 (gmt 0)

10+ Year Member



explicit path from the server root?

that's what I'm trying to do. I want to use the global constant (the site's root url) as a base for all links and includes and stuff.

ex:

$baseurl = "www.schmuck.com/horatio/fava"

so even if I'm in a script in the "www.schmuck.com/horatio/fava/wonk/special/glob/" directory, I can call "www.schmuck.com/horatio/fava/dog/stuff.php" by saying

include("$baseurl/dog/stuff.php");

I'm sorry, maybe it's just a simple thing I'm not thinking of, but do you know what I'm saying now? How would I do what I'm trying to do?

ergophobe

10:59 pm on Nov 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




so even if I'm in a script in the "www.schmuck.com/horatio/fava/wonk/special/glob/" directory, I can call "www.schmuck.com/horatio/fava/dog/stuff.php" by saying

include("$baseurl/dog/stuff.php");

That should work just fine but you must specify a protocol ("http://www.example.com/horatio....").

There are two improvements you can and should make, though.

For SPEED use the file system, not the web server

include("/home/htdocs/animals/dogs.php");

For PORTABILITY set a constant based on he server-determined document root

define('DOC_ROOT', $_SERVER['DOCUMENT_ROOT'] . "/animals/");
include(DOC_ROOT . "dogs.php");

ocelot

6:23 am on Nov 26, 2004 (gmt 0)

10+ Year Member



well is there a way to have the constant "just there" though, so I don't have to put define(server[]..blahblah) in every script?

supermanjnk

2:50 pm on Nov 26, 2004 (gmt 0)

10+ Year Member



<?
ini_set('include_path', realpath($_SERVER['DOCUMENT_ROOT'] . '/b_site/include/') . '.' . PATH_SEPARATOR . ini_get('include_path'));
?>

this will make it so that all your includes will default to widgets.com/b_site/include/

put that in a folder called include in your includes folder.

then at the top of your page put

<? include ($_SERVER['DOCUMENT_ROOT'].'/b_site/include/config.php');?>

and every other include on the page will just need to be

<? include ('header.php');?>

hope that makes sense