Jump to content

Include Problem


lakeccrunner

Recommended Posts

I've been using the php Include function for a while now, but I used to use it for individual pages. Now, I want to have the files in one place, and be able to update them.

 

before I was using the traditional <?php include("include.php") ?>

 

But I can't figure out how to recode it so I can have the include.php in the main directory and nowhere else.

 

Thanks in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/81060-include-problem/
Share on other sites

Is it possible it's not working because the file I want to work is in located in a directory such as www.mydomain.com/derector1/directory2/file.php?

 

Yes its possible, in fact likely seeing as your question was....

 

But I can't figure out how to recode it so I can have the include.php in the main directory and nowhere else.

 

When you said main I assumed root.

Link to comment
https://forums.phpfreaks.com/topic/81060-include-problem/#findComment-411545
Share on other sites

Yeah you just need to specify the correct path to it.

<?php
include("/home/USERNAME/public_html/PATH-TO-FILE/FILENAME.php");?>

where username is the username you use to login to your website account, path to file is the path to the file (/folder/ for example) and filename is the name of the file.

 

Or as thorpe posted,

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

and just modify the path. So if it's in /directory/directory/include.php...

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

Link to comment
https://forums.phpfreaks.com/topic/81060-include-problem/#findComment-414559
Share on other sites

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.