Nov 12 2008
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.
40 Responses so far
-
*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)
-
THANK YOU THANK YOU THANK YOUUUUU.
-
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. :(
-
@Jem: Still going for “more bloggy”?
-
Rasmus Lerdorf? Isn’t that a type of salad?
-
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?
-
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. :P
-
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.
-
… 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 -
Similar to how tables aren’t meant for layouts. Ah, where would we be if no one used those?
-
But Jem, I use PHP includes so I KNOW PHP. DUH.
-
I WANT VERDANA BACK :’(
-
Really? People don’t get this? I got this immediately after I implemented them into my site, way back on Mirkwood Wench! :P
But I think a “Jem-has-big-boobies” revolution would do nothing but help the web community. ¬_¬; Heh!
-
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!
-
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
-
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.
-
?php echo “hello world”; ?
Yay I know php!
-
PHP is a coding language and HTML technically isn’t. That’s the distinction, I think, some people don’t understand.
-
Amen to that. :P
-
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.
-
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…
-
I hate it when people have tutorials on “How to use PHP” and it only shows dumb stuff about includes :(
-
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. :P 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.
-
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.
-
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…
-
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.
-
lol i tried to learn php so i know it when i get hosted but a failed :P
-
Use the new layout IMO
-
Please don’t reverse it, that hurts my eyes…too much white. I much prefer this layout.
-
THANK YOU for writing this!
-
BTW, have you been to pixelfx lately? Haven’t looked at the tutorials yet, but there finally has a new layout up…
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…?
-
(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.
-
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.
lol i tried to learn php so i know it when i get hosted but a failed
… huh?
-
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.









