PHP Includes Aren't What You Think
Newsflash: knowing how to do implement PHP include() doesn't mean you "know" PHP, sorry and all that. Yes indeed, I hate to be the bearer of bad news, but this cool "layout technique" you've learned isn't a layout technique at all. It has nothing to do with layouts. In fact, PHP and design are two entirely different subjects altogether.
The PHP function (well, statement really) include() is a means by which to ... wait for it, you'd never guess this one: include one file in to another. That means that yes, when you put your meta tags/etc in to header.php and reference it using <?php include('header.php'); ?>, you're using it right. However, no, this was not what Mr Rasmus Lerdorf had in mind when he implemented the bloody thing. (No, I have no facts to back this up. Shut up.)
Funnily enough, if you were to create a file called jem-has-big-boobies.php and use: <?php include('jem-has-big-boobies.php'); ?>, that would work too! The filenames header.php and footer.php aren't a magical tool by which you tap in to some secret PHP functionality to make your website really l33t, honest.
Don't get me wrong, I'm not advocating you all go out and start creating jem-has-big-boobies.php includes — as fucking hilarious as that would be — and I'm not suggesting that you're doing something wrong by using the functionality of PHP's include(). I am however begging those of you who don't understand why or how it works to spend a little time with my friend the PHP manual. It doesn't bite, I promise.
Comments (39)
Leave a Comment
No HTML (it will be stripped); first time comments are moderated; comments left without a legitimate first name/nickname and e-mail will be deleted (no, your momma didn't call you "cheap quality wardrobes").




On Wed 12th Nov 2008 @ 19:43, Tracy said:
*thinks about big boobs* ... you were saying?
Anyways, yes, PHP. It's not THAT easy. Once I'm done with my studies I need to concentrate on learning it. What I've learned in uni isn't enough. I was proud that I could create my navigation though AND add links from my DB to my site
(well... with a little help from you)
On Wed 12th Nov 2008 @ 19:44, Stephanie said:
THANK YOU THANK YOU THANK YOUUUUU.
On Wed 12th Nov 2008 @ 20:05, Stephanie said:
What, really? And all this time I thought I knew PHP. I'm so going to include a jem-has-big-boobies.php file in my WP template somewhere now that I know that that's what PHP really is.
Also, your asides are gone.
On Wed 12th Nov 2008 @ 20:28, Jem said:
They're now in the main body of text. I'm still fiddling though...
On Wed 12th Nov 2008 @ 20:37, Stephanie said:
@Jem: Still going for "more bloggy"?
On Wed 12th Nov 2008 @ 20:38, Josh said:
Rasmus Lerdorf? Isn't that a type of salad?
On Wed 12th Nov 2008 @ 20:43, Carly said:
I was looking through all the includes in the websites at work - thought they all use the header / footer / menu etc (we use a load more too) they all also seem to written in different ways. Some use DOCUMENT SERVER ROOT or something before the path, some have these: ' some use none of those, and some have ( and some don't. Is there one correct way of doing it?
On Wed 12th Nov 2008 @ 20:44, Jem said:
TBH, if your file works as intended, then you've done it right
On Wed 12th Nov 2008 @ 20:53, Joe said:
Half the 12-year-olds who do this probably don't even realise that PHP is something completely separate from HTML.
The idea that they can actually do more than just split their files up into headers probably hasn't occurred to them either.
It's probably good that they're none the wiser: If they learned what can actually be done with PHP, incredibly shit and insecure scripts are going to start popping up everywhere.
On Wed 12th Nov 2008 @ 20:59, Roxanne said:
Whoa, I thought this was common knowledge! Guess not...or that could be me just being ignorant... =P
Side-Note: I see your editing the look of your blog. I actually liked the comments links underneath the blog title...easier to find! Personal opinion of course.
On Wed 12th Nov 2008 @ 21:02, Vera said:
... but but but I was CERTAIN that my layout was so 1337 now... *chucks entire site away in a huff*
Meh, for a beginner the PHP manual can be quite a "mouthful" though. But then again, coding is not for everyone, or else everyone would be a programmer XP
On Wed 12th Nov 2008 @ 21:08, Robert said:
Similar to how tables aren't meant for layouts. Ah, where would we be if no one used those?
On Wed 12th Nov 2008 @ 21:09, Clem said:
But Jem, I use PHP includes so I KNOW PHP. DUH.
On Wed 12th Nov 2008 @ 21:38, M said:
I WANT VERDANA BACK
On Wed 12th Nov 2008 @ 21:58, Jacky said:
Really? People don't get this? I got this immediately after I implemented them into my site, way back on Mirkwood Wench!
But I think a "Jem-has-big-boobies" revolution would do nothing but help the web community. ¬_¬; Heh!
On Wed 12th Nov 2008 @ 22:37, Jem said:
Yeah, I'm not so sure about the Arial yet myself...
On Wed 12th Nov 2008 @ 22:56, Stephanie said:
Whoa, the asides are now in the main body of the text. (Yes, I see your comment.) Okay, they're not gone. That's helpful. But, well, I never did like seeing them in the main body... for some reason that just confuses me. Personal preference. I did use your tutorial on how to do that to implement my own 'asides', so thanks for that!
On Wed 12th Nov 2008 @ 23:04, Liz said:
Sadly I actually have seen php includes as a tutorial on very "trendy" sites. lAWLZZ new layout technique instead of iframes! Ahaa I should name my header Jem-has-big-boobies.php
On Wed 12th Nov 2008 @ 23:42, Vasili said:
I was going to write an article like this... IF MY SITE WORKED FOR ME. >:( I was scared of the PHP manual in the beginning, but now I can't live without it.
I don't like the asides plus posts mixed together; the padding confuses me.
On Thu 13th Nov 2008 @ 00:57, Louise said:
?php echo "hello world"; ?
Yay I know php!
On Thu 13th Nov 2008 @ 01:22, Audrey said:
PHP is a coding language and HTML technically isn't. That's the distinction, I think, some people don't understand.
On Thu 13th Nov 2008 @ 02:46, Hannah said:
Amen to that.
On Thu 13th Nov 2008 @ 04:51, Melissa said:
Haha! So true. I've been using includes for ages and I adore them, but I would never go around saying I'm a PHP ninja! I'm just pretty happy if my sites load from day to day without errors.
On Thu 13th Nov 2008 @ 05:21, Adrianne said:
LOL. Don't forget those who download a PHP script from some site (yours, for example, Jem), fill in the fields where the comments say "change this to (this)", implement it on their sites and then claim to the world they know PHP. (sadly I've run across sites in which the owners actually claim this...)
Although you gotta admit that the PHP's include() is heaps better than HTML frames. Even until now I still see some sites who still use frames. Hm...
On Thu 13th Nov 2008 @ 07:32, Anita said:
I hate it when people have tutorials on "How to use PHP" and it only shows dumb stuff about includes
On Thu 13th Nov 2008 @ 10:17, Julia said:
I've always known that includes isn't PHP altogether. Its a statement that is used to include files.
Nice name for the example file.
You can call the file whatever you want & it will include itself.
I'll try reading your PHP manual & see if I can understand PHP more.
On Thu 13th Nov 2008 @ 11:34, Julie said:
Did you have a specific person in mind? It's late (or early, I'm not sure which by now) and I want some entertaining dramuh, which is hard to cause without some good ol' finger pointing.
On Thu 13th Nov 2008 @ 11:48, Jem said:
Nah, this is pretty common Julie.
On Thu 13th Nov 2008 @ 12:07, Julie said:
I know, but I was still hoping fun would ensue.
BTW, have you been to pixelfx lately? Haven't looked at the tutorials yet, but there finally has a new layout up...
On Thu 13th Nov 2008 @ 12:09, Jem said:
Yep! The tutorials still suck...
On Thu 13th Nov 2008 @ 16:27, Mike Haddad said:
Been a long time since I've had a chance to use PHP (I've been stuck with Java in school for the last little bit, and it's eaten up all of my time), but I seem to remember include() not being limited to just php either. That might melt some brains.
On Thu 13th Nov 2008 @ 19:18, Jamie said:
lol i tried to learn php so i know it when i get hosted but a failed
On Thu 13th Nov 2008 @ 20:19, Amber said:
Use the new layout IMO
On Thu 13th Nov 2008 @ 20:42, Mumblies said:
Please don't reverse it, that hurts my eyes...too much white. I much prefer this layout.
On Thu 13th Nov 2008 @ 20:56, Vanesa said:
THANK YOU for writing this!
On Thu 13th Nov 2008 @ 21:19, Carly said:
It makes me laugh it's a tutorial site, using a premade layout. Also the text is hard to read, dunno if it's cus of the mac - or if everyone thinks it...?
On Thu 13th Nov 2008 @ 23:54, Zatanna said:
(No, I have no facts to back this up. Shut up.)
*giggles*
I never thought that I knew PHP when I first discovered PHP includes. I was just relieved that I didn't have to edit every page of my web site to add/take out something. Plus I'd take one look at (any) PHP script and know that's what PHP really was.
On Fri 14th Nov 2008 @ 07:03, Mimi said:
I was actually explaining includes to someone today and I referred them to your tutorial on Tutorialtastic. I believe you mention something about this near the bottom of the page, no? Not quite in the same manner but.. ah! This was entertaining to read nonethless.
... huh?
On Sat 15th Nov 2008 @ 23:31, Lewis Walsh said:
Just an FYI:
If the file you are 'including' can not be found then the PHP script will continue to run without it, though you will most likely see a warning report.
If you use require() or require_once() instead of include() then your PHP script will halt if the required file can not be found. This can save a lot of problems if database queries are executed based on data from an include() that couldn't be found.