Welcome to WebmasterWorld Guest from 50.17.79.100

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

     

crash41

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

5+ Year Member



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

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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

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

5+ Year Member



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

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

5+ Year Member



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

bkeep

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

5+ Year Member



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

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

5+ Year Member



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

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

5+ Year Member



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

ncw164x

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

WebmasterWorld Senior Member 10+ Year Member



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

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

5+ Year Member



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

crash41

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

5+ Year Member



Got it- dude. i'm an idiot.

thank you all!

ncw164x

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

WebmasterWorld Senior Member 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month