Jump to content

Question about 'include'


Cordyceps

Recommended Posts

Hi,

 

First I'll say that I know approximately nothing about PHP. So..

 

<?php include '/menu.php';?>

 

^ I've been using that as a way of easily applying changes to the menu, footer, etc. for all pages. It works fine on localhost (XAMMP), but when I upload all the files, I get error messages - I know this has something to do with the path because when I take out the "/" (I guess when I do that it looks in the server's root directory?), it works, but only for pages in the site's root directory (since that's where the files are). I guess my question is, is there a simple way of telling it to look in the site's root directory (not the server's - that does work, but I don't want to do it that way) for the file to include?

 

I've tried to do it a few different ways, like

 

<?php include $_SERVER['DOCUMENT_ROOT'] . '/menu.php';?>

 

but nothing seems to work... I just get more or less error messages, and nothing shows up.

 

Also, if there's an easy alternative to what I'm trying to do, feel free to mention it.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/187141-question-about-include/
Share on other sites

make a config file that has something like

$path='/home/joebloe/public_html';

$url='http://domain.com';

$url_img="$url/images";

 

then include it into your page.

include('/home/joeblow/public_html/includes/config.php');

 

Then you can do things like

 

$file='text/file.txt';

file_get_contents("$path/$file");

 

and

$img_file='this_pic.jpg';

<img src="<?php echo "$url_img/$img_file"; ?>" border=0>

 

 

HTH

Teamatomic

Archived

This topic is now archived and is closed to further replies.

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