homepage Welcome to WebmasterWorld Guest from 54.227.67.175
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Includes are not working
files in sub-directory do not show the include effects
mvaz




msg:4628655
 8:15 pm on Dec 7, 2013 (gmt 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

 

not2easy




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

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.

lucy24




msg:4628672
 10:41 pm on Dec 7, 2013 (gmt 0)

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?

not2easy




msg:4628673
 10:59 pm on Dec 7, 2013 (gmt 0)

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.

lucy24




msg:4628676
 11:55 pm on Dec 7, 2013 (gmt 0)

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.

mvaz




msg:4628677
 12:19 am on Dec 8, 2013 (gmt 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.

penders




msg:4628990
 3:21 pm on Dec 9, 2013 (gmt 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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved