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
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
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
Share on other sites

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.