Forum Moderators: coopster

Message Too Old, No Replies

menu system with php

         

kumarsena

2:15 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



anyone have any idea of how to use just one include file for menus and make it available for documents further down in the file system. i tried something like this..."/folder/file.php" and "/file2.php" in the include file but smething goes wrong. it seems like its starting from the root of the server (or my account i guess) and not public_html...would using the whole URL have any effect on the speed of loading? any ointers to related articles would be apreciated.

thanks

HelenDev

2:24 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tend to use the whole URL in my menu include files, so I can put them on any page in the site without worrying. If I changed domains there would only be a handful of include files to amend anyway.

I have no idea whether this slows anything down, but it seems to work for me.

nostra

4:04 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



i think you could solve it at follows:

you have a rootdir:
e.g. /wwwroot/
news are in
/wwwroot/news/news.php
events are in
/wwwroot/events/events.php
and refs are in
/wwwroot/refs/refs/refs.php

and your navigation/menu file is in
/wwwroot/cms/menu.inc

so define in news and events:
e.g.:
define ("PATH_BASE","../");
and in refs.php
define ("PATH_BASE","../../");

now you can include your menu file like
require (PATH_BASE."cms/menu.inc");

i hope, i've understood what you mean

encyclo

4:24 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try something like:

<?php include($_SERVER["DOCUMENT_ROOT"]."/folder/file.php");?>

That completes the path to the document root (public_html), and is transferrable from one server to another, even when the actual path changes.

jetboy_70

4:31 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



I *think* I know what you mean ...

PHP will only include files if they are located in one of the directories specified in 'include_path' in the php.ini file. Usually, the first path specified is '.', which translates as the current directory. This is why you can only include files in the same directory as your calling file, and any attempts to build a path to a file in a different directory fail.

If you are using an ISP's PHP implementation, they have probably specified an include directory already. To find out, make a tiny PHP file with this code in it:

<?php phpinfo();?>

Save the file as phpinfo.php and FTP it up to your domain. Run the page in a browser:

http:// yourdomain / phpinfo.php

This will give you the specs for your PHP implementation. Hit ctrl+F in your browser to open up a search box, and search for 'include_path'. This will give you the allowed include path for your site. You should see 'public_html' in there, and any further directories are subdirectories of your site.

If there's nothing listed, or if for some reason you need to specify another path, you can add a line to your .htaccess file (assuming you haven't got access to php.ini) to add new paths. If you need to know how to do this then let me know.

isitreal

5:13 pm on Mar 23, 2004 (gmt 0)

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



Another easy way to set your include path is this:

1. get the server root path by running this command on a page:
<?php echo $_SERVER["DOCUMENT_ROOT"]?>

2. Download your .htaccess file, than add this line to it:

php_value include_path ".:/usr/www/your_main_site_folder/includes"

Change the path to what you got from the document root information.

Make sure you put a linebreak after this addition, then upload the .htaccess file in ASCII (text) mode.

Now all your includes will look for this path no matter where they occur in your site.

coopster

8:00 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>...any pointers to related articles would be apreciated.

OK! Here's a couple:

Accessing PHP includes folder in root dir from 2+ levels deep [webmasterworld.com]

Some tips and tricks in this thread [webmasterworld.com] and it's related links may help too.