Forum Moderators: coopster

Message Too Old, No Replies

Using php include

         

Mr_Cat

1:55 pm on Nov 28, 2008 (gmt 0)

10+ Year Member



Hi folks, I'm new to php and have just started using the php include function to try and better organise my site as it grows.

i.e. php include("mainmenu.php") on all my pages etc.

Very handy, but is there a problem with using absolute links in it?
I have found that php include("http://www.example.com/mainmenu.php") doesn't work?

I'm wondering how to include appropriate files once the directory structure of the site gets more complex?

Thanks
Mr Cat

g1smd

1:57 pm on Nov 28, 2008 (gmt 0)

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



Use

include '[b]/[/b]the-path/the-file-name.php';

instead.

Don't include the domain name.

There is never a need to include "http" because the file is included internally within the server. It isn't the browser fetching this individual file. It is the server doing all the work.

I usually have a special folder for include files, to keep them separate from the rest of the website.

Mr_Cat

2:08 pm on Nov 28, 2008 (gmt 0)

10+ Year Member



Brilliant!
Thanks :)

TeofenGL

8:45 pm on Nov 28, 2008 (gmt 0)

10+ Year Member




When "never" happens and you DO need to include files remotely, it's *possible* to include remote files over http/ssh/etc, targeting both remotely-parsed and locally-parsed files, and to send variables to remotely parsed files. This can be very useful.

[php.net...]
(Example #3)

vincevincevince

8:19 am on Nov 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An invaluable expression is:

include("$_SERVER[DOCUMENT_ROOT]/includes/file.php");

The DOCUMENT_ROOT member of the server array always points to the root of the site, even if you copy the system to another site or your server admin changes the server paths.