Forum Moderators: coopster

Message Too Old, No Replies

Newbie question on placement of PHP functions

where do I put these?

         

kenfused

7:30 am on Aug 16, 2005 (gmt 0)

10+ Year Member



On my site, i have a few php scripts.
I've been trying to put them in a directory called functions, although one of my php scripts is in the root directory, while my main css file is also in the root directory

In my PHP pages, I have

<?php require('../functions/a_lite.php');?>
<?php require('../allphp.php');?>
<link href="/test.css" rel="stylesheet" type="text/css">

This code is in a page that resides in www.mysite.com/directory

If I make a page in www.mysite.com/directory/subdirectory, I have to change this to

<?php require('../../functions/a_lite.php');?>
<?php require('../../allphp.php');?>
<link href="/test.css" rel="stylesheet" type="text/css">

How do I do this without having to keep adding "../" in the require statement?
I tried "/functions/a_lite.php" as the require statement, but it doesn't work.
I want to avoid having the "../../../../" all over the place when I go deeper into directories!

Thanks!

coopster

11:29 am on Aug 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at message number 17 regarding how to Control your included files in Good PHP solutions to small problems [webmasterworld.com].

kenfused

4:53 am on Aug 17, 2005 (gmt 0)

10+ Year Member



Thanks!
Sounds interesting.

Where exactly does this code go?

coopster

7:19 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You can put it at the top of your script. But the main reason I showed you that was so you could see how you could build your path dynamically.

kenfused

8:54 pm on Aug 18, 2005 (gmt 0)

10+ Year Member



Oh, I see...

So i put this at the top of each page where I need to "include" my scripts.

ini_set('include_path',
realpath($_SERVER['DOCUMENT_ROOT'] . '/../includes/')
. PATH_SEPARATOR
. ini_get('include_path'));

I can change "/../includes/" to "/../functions/" in my case since I put my php inside /functions/ ?

Thanks