homepage Welcome to WebmasterWorld Guest from 107.20.25.215
register, free tools, login, search, pro membership, 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

    
Question in regards to dynamic content code
php error
brettxw




msg:4263976
 11:16 pm on Feb 7, 2011 (gmt 0)

Hey guys, I am using the following code to include an .html :

<?php
include('header.html');
?>


You can view the error(s) I'm getting by looking at the actual page :

[updateyourblackberry.com...]


My header.html, navbar.html and footer.html are all in the /new/ folder, not in the /new/devices/ folder. I tried changing the code to

<?php
include('new/header.html');
?>


and some other variations with no luck. How do I change it so I can get these .html files that are located at www.updateyourblackberry.com/new/header.html and /navbar.html and /footer.html to appear?

Any help would be greatly appreciated.

 

brettxw




msg:4263979
 11:21 pm on Feb 7, 2011 (gmt 0)

I even tried ./header.html and that doesn't work.

brettxw




msg:4263983
 11:26 pm on Feb 7, 2011 (gmt 0)

Update - Mods can delete this thread, I figured out what I was doing wrong.

g1smd




msg:4263984
 11:30 pm on Feb 7, 2011 (gmt 0)

... and for the benefit of the next person with the same problem, what was the answer?

brettxw




msg:4263997
 11:42 pm on Feb 7, 2011 (gmt 0)

If it is one directory below

<?php
include('../header.html');
?>


two directories below

<?php
include('../../header.html');
?>

brettxw




msg:4266016
 6:15 am on Feb 12, 2011 (gmt 0)

What is the difference between this code...

<?php get_footer(); ?>


and

<?php
include('header.html');
?>

g1smd




msg:4266047
 9:03 am on Feb 12, 2011 (gmt 0)

Avoid the ../../ notation, it will surely confuse in the end.

Specify the full path to the file beginning with a leading slash to count from the root.

fredfletcher




msg:4266187
 6:06 pm on Feb 12, 2011 (gmt 0)

I'm no programmer as perse, yet I personally like to use root to folder/file syntax myself:

<?php
include('/root_of_server/folder/file_in_question.html');
?>

that way, you can't go wrong, it will go to the root of your server and find the folder/file you wish to include.

fredfletcher




msg:4266189
 6:16 pm on Feb 12, 2011 (gmt 0)

Brett,

your question about the difference between:

<?php get_footer(); ?>


and

<?php
include('header.html');
?>

get_footer() is a function, that once set, can be used over and over again in different parts of your document. (Correct me if I'm wrong) ;0)

that's the best answer I can give you with the capabilities I have, and I always or most of the time, find the answers to my questions on Google and this great site :) people are very nice here and help me out a great deal, as well as others :)

have a look at this page, which may be of help to you:

[forums.zend.com...]

...unless you can find it on this site.

Cheers!

brettxw




msg:4266217
 8:12 pm on Feb 12, 2011 (gmt 0)

Oh, thanks for the information guys! I've been learning a lot from this site!

Matthew1980




msg:4266251
 10:28 pm on Feb 12, 2011 (gmt 0)

>>Avoid the ../../ notation, it will surely confuse in the end.

Ah, this is something that will make your coding standards terrible if you carry on in this way, define the ROOT_PATH as a constant in the 'root' of your site directory, define('ROOT', dirname(__FILE__)); or even use the predefined $_SERVER['DOCUMENT_ROOT'] global.

But seriously, don't go the toothpick way because maintaining the code will turn into a nightmare, at least with the constants, they are global - available to the entire scope of your site.

Another difference to your question: the include() function is one of those functions that you can use WITHOUT the parenthesis, just like echo, die, exit etc. I just thought I would throw that into the ring ;)

Cheers,
MRb

brettxw




msg:4266274
 12:08 am on Feb 13, 2011 (gmt 0)

okay so I am getting confused with the ROOT code....I'm trying to show my footer.html which is located:

/public_html/footer.html

on my dedicated server but I get the

"Warning: main(/public_html/footer.html) [function.main]: failed to open stream: No such file or directory in /home/brettxw/public_html/subs/blog/wp-content/themes/twentyten/footer.php on line 33" error

brettxw




msg:4266288
 1:33 am on Feb 13, 2011 (gmt 0)

Well I answered my own question. Answer was hiding in the error.

g1smd




msg:4266345
 9:13 am on Feb 13, 2011 (gmt 0)

Yup!

fredfletcher




msg:4266493
 5:11 pm on Feb 13, 2011 (gmt 0)

glad it worked out for you Brett, and yes this is a good site, that's why I'm here too :)

rocknbil




msg:4266934
 6:05 pm on Feb 14, 2011 (gmt 0)

A bit more that might help you - the "why" of what went wrong here.

New PHP coders tend to think of includes as just another URL. When you do an include, you are including a file by a system path, which is what you are seeing your error.

What makes it confusing is sometimes they look the same. If you have this structure,

myfile.php
includes/header.php

The URL and systme path are the same, because they both start "wherever myfile.php is now."

But when you do this

/public_html/www/my_widgets/myfile.php
/public_html/www/includes/header.php

You get into the toothpick syndrome ../ or . . . you learn to use system paths for includes, url's for links.

What makes this important is when you start moving files around. You will always access header.php via an include like this,

$_SERVER['DOCUMENT_ROOT'] . "/includes/header.php"

Or via URL like this (not that you'd want to,)

/includes/header.php

(/ means "start at domain root" in URL's)

but if you use slash-dot syntax, you''l be in endless maintenance to update the number of dots and slashes.

<?php get_footer(); ?>

This is specific to WordPress, one of the most popular blog softwares out there, not a real fan of their coding style. But it's a success, so, not knockin' it. :-)

fredfletcher




msg:4266937
 6:17 pm on Feb 14, 2011 (gmt 0)

Thanks for the info Rockn! much appreciated

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