homepage Welcome to WebmasterWorld Guest from 54.161.191.254
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Can't figure out php include for the life of me :(
crash41




msg:3831445
 5:14 pm on Jan 21, 2009 (gmt 0)

I'm somewhat new to php (understatement).

We simply want to use php includes to reference the header and footer of a site. When the files are in the same directory - all is good. But they won't be. When i move them to where they will live - i get errors.

Any ideas? I've tried using the document root and nothing seems to help.

[edited by: eelixduppy at 5:47 pm (utc) on Jan. 21, 2009]
[edit reason] no personal URLs, please [/edit]

 

eelixduppy




msg:3831481
 5:48 pm on Jan 21, 2009 (gmt 0)

Do you have permissions to the files where they are now? Are you using the correct path? Everything spelled correctly?

There are a bunch of things that could be going wrong. Are you getting any errors from the script you are trying to include these files into?

crash41




msg:3831555
 6:54 pm on Jan 21, 2009 (gmt 0)

Good question. How can i find that out? It does work when the include file is on the same level as the page i'm accessing

crash41




msg:3831556
 6:55 pm on Jan 21, 2009 (gmt 0)

As for the correct path - that might be my issue. I can't figure out how to code it.

bkeep




msg:3831574
 7:16 pm on Jan 21, 2009 (gmt 0)

when including a file I use relative paths so if the files are in the same directory lets say / you include the file like this

include_once 'header.php';

If you move the header into a directory say /includes/

include_once 'includes/header.php';

Good luck

crash41




msg:3831602
 7:46 pm on Jan 21, 2009 (gmt 0)

What is the main file is about 3 levels DOWN (into) the site?

for example site struture is:

site/issues/naked/file.php

i want to include a file that is on the 'site' level. how do i do that?

bkeep




msg:3831621
 8:03 pm on Jan 21, 2009 (gmt 0)

include_once '../../../header.php'; give or take a "../"
.. is up one level . is the current level

ncw164x




msg:3831656
 8:53 pm on Jan 21, 2009 (gmt 0)

you need to use the full server path to the include file and not the url of the site

<?
include ("/what/ever/the/full/sever/path/to/the/include/file/is/footer.php");
?>

then you need to make a file with whatever name you want to use, the example above would require a file name called footer.php, this can be any name you want it to be

crash41




msg:3831657
 8:54 pm on Jan 21, 2009 (gmt 0)

Cool - that helps. But how to i know what the full server path is?

crash41




msg:3831699
 9:22 pm on Jan 21, 2009 (gmt 0)

Got it- dude. i'm an idiot.

thank you all!

ncw164x




msg:3831723
 10:00 pm on Jan 21, 2009 (gmt 0)

no problem glad you got it sorted ;)

for the sake of anyone else looking to solve the same problem the full server path will be visible on the remote connection of the FTP program what is used to transfer your files

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