Jump to content

Problem with include statement


Go to solution Solved by Texan78,

Recommended Posts

I am having some problems with an include statement. Seems like a very simple task but, for some reason probably due to lack of knowledge it isn't working. 

 

Here is the layout of the folder structure I am working with for example. The pages are in a sub-domain. Sub-domain is called media. The index page is in media > network > kdfw > index.php

 

The index.php is the file in which I am trying to include the file in. 

 

The included file is  in media > network > kdfw > inc

 

These are the methods I have tried...

<?php include '/media/inc/chaserData.php'; ?>

<?php include 'media/inc/chaserData.php'; ?>

<?php include '/inc/chaserData.php'; ?>

<?php include 'inc/chaserData.php'; ?>

<?php include ($_SERVER['DOCUMENT_ROOT'].'/media/inc/chaserData.php'); ?>

<?php include ($_SERVER['DOCUMENT_ROOT'].'media/inc/chaserData.php'); ?>

<?php include ($_SERVER['DOCUMENT_ROOT'].'/inc/chaserData.php'); ?>

<?php include ($_SERVER['DOCUMENT_ROOT'].'inc/chaserData.php'); ?>

None of the above work and I am not sure as to why. 

 

Is there anyone who could provide some insight and shed some light to this issue?

 

-Thanks

 

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

Thanks, I have tried that too with my many combinations. That does not work ether. 

 

This is the error I get in the error log trying the above suggestion. I am not sure if this is because it is in a sub-domain or what but I am having all kinds of trouble using include statements. Even in my dbinfo.php file I use in my script that calls data from a MySQL I had issues and had to use ($_SERVER['DOCUMENT_ROOT']  before that include statement to even get that to work. 

Anyways, here is the error from using the suggestion you mentioned. 

 

 

[17-Aug-2016 22:54:02] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '../inc/chaserData.php' for inclusion (include_path='.:/usr/lib64/php:/usr/share/pear') in /home2/livestp1/public_html/media/network/kdfw/index.php on line 40

  • Solution

I got it sorted out by using this below. I am not sure if this is the correct method but, it works. I think because it is an addon domain and the files are in a sub-domain of the add on domain the normal method doesn't work as normal I am assuming. 

<?php include($_SERVER['DOCUMENT_ROOT'].'/network/kdfw/inc/chaserData.php'); ?>

The DOCUMENT_ROOT method is the best method. Remember that it starts at the root of your website (which is apparently "media"), not the current directory.

 

Using __DIR__ is the second best method and is relative to the current directory.

include(__DIR__ . "/inc/chaserData.php");
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.