Welcome to WebmasterWorld Guest from 23.20.75.214

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Includes are not working

files in sub-directory do not show the include effects

     
8:15 pm on Dec 7, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 10, 2006
posts: 140
votes: 0


Hello there, this could be something very simple or something that my weary eyes cannot figure out the obvious.

I have my header.inc.php file in the includes folder.

When I include this file for a file within a subfolder (newdesign) using the following, it works like a charm.

include_once($_SERVER['DOCUMENT_ROOT'] .'/newdesign/includes/header.inc.php');

However, if I am using this for a file within another subfolder (forms) it is not working.

Directory structure is as below:
root -> newdesign -> includes (works fine here)
root -> forms -> and a php file in here (fails to work here)

Where have I gone wrong? any ideas please?

Regards

Melwyn
10:40 pm on Dec 7, 2013 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:2763
votes: 64


If your header.inc.php file is located inside the /includes/ folder of the newdesign directory as shown, it is not in directory you are trying to use it in. The simplest solution is to create a copy of the /includes/ folder in the /forms/ directory and then it could conceivably use the path you are using.
10:41 pm on Dec 7, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13210
votes: 347


Dang it, I was about to post a question with the identical subject line and now I'll have to think of something else.

Is the ultimate document --the one that the user sees-- html or php? Does the include file have parameters? Does anything behave differently if you step out of php and configure the include as an SSI instead? I throw out these questions because they played a role in my own (unrelated) problem.

it is not in directory you are trying to use it in

Isn't that what $_SERVER['DOCUMENT_ROOT'] is for?
10:59 pm on Dec 7, 2013 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:2763
votes: 64


Isn't that what $_SERVER['DOCUMENT_ROOT'] is for?


Actually that part is not needed, but the folder has to be on the same directory level, the same path. Things I learned the hard way. I don't know anything about php except using includes, but generally the server can't process the request and a look at error logs with give you a message about headers already sent.
11:55 pm on Dec 7, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13210
votes: 347


the folder has to be on the same directory level, the same path

That can't be right. If it were, then the line
include ($_SERVER['DOCUMENT_ROOT'] . "/includes/fullfooter.html");

would never work, because it only occurs in files that are not, themselves, in the /includes/ directory.
12:19 am on Dec 8, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 10, 2006
posts: 140
votes: 0


Thanks Lucy24 and not2easy for your input on this.

@not2easy, the header.inc.php file is inside the include directory under the root. It works for all files under the root directory, but does not for files within sub directories under the root (in my case root -> forms).

@lucy24, addressing your questions, the ultimate document is a php file (.php) which includes the header file. The biggest issue I have is that the header file has the link to the css and that is throwing the entire page out of sync.

@not2easy, your solution would work at this time, but the issue still remains unresolved - why and how to get his working having the include in just one place under the include folder; replicating it in every subfolder would not be and ideal solution.
3:21 pm on Dec 9, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0


include_once($_SERVER['DOCUMENT_ROOT'] .'/newdesign/includes/header.inc.php');


This should work. In so far as "header.inc.php" should be included from any document. What exactly "fails to work"?

(The whole point of $_SERVER['DOCUMENT_ROOT'] is that it makes it an absolute path, accessible from anywhere.)

The simplest solution is to create a copy of the /includes/ folder in the /forms/ directory...


What?! That defeats the whole purpose of having an "includes" folder in the first place!

That can't be right.


Agreed. It's not right!