Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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