14 Apr

HTML Includes Are Here

We are all used to the joy of being able to split up our key page elements using PHP and include them at will, eliminating the repition of large chunks of code in creation and editing, but it always bothered me that i would either have to change all pages to .php or use (heaven forbid) DreamWeaver templates to achieve this.

Not any more, ..HTML includes are here, with a little help from our ever more dependable friend JavaScript.

I won’t bore you with the details, head on over to the Official Hinclude Page to read all about it, ..as you may not be too surprised to here it follows the emerging pattern of JS file in header ,and then covert call in code.

Very very simple, …..but with one slight point of interest, of which i have not decided if it is a plus or a minus yet. Hidden source.

You see the page will uses a CLIENT side include rather than a SERVER side include, which of course has big advantages in terms of loading times and monopolizing the browsers caching abilities, ..again read the technicalities over at Hinclude, ..what i think is interesting is this potential hiding of source, …which of course is not truly hidden (view source, find url, paste link into browser). …but it does mean that essentially code can be hidden from search bots.

Why would you want to do this, …a few reasons spring to mind, most slightly dubious, but nonetheless, reasons spring to mind :)

For you, i will leave you to make your own mind up, ..and if you are interested in seeing a stripped down verson, i have setup this naked Hinclude Test Page on my server.

If you enjoyed this post, make sure you subscribe to my RSS feed!

6 Comments

  1. 1
    Arthur
    April 25, 2008 at 3:48 pm
    Permalink

    I thought that simple convention is to name all segments as segment_name.inc when you include() or require()???

  2. 2
    mog
    April 27, 2008 at 5:41 pm
    Permalink

    DEFINITELY NOT, ..when you name a file with the extension .inc if it contains PHP and you include it, then as long as the page into which it is being included is PHP, the PHP will be parsed fine, ..BUT …should a user navigate manually to this page, they will be able to view all of the RAW PHP as the browser treats the .inc extension as a TXT file, …which of course is a HUGE SECURITY RISK.

    However, this is all related to PHP includes using include() and require(), what this post was illustrating were file includes using JUST HTML and JS, (CLIENT-SIDE, not server-side)…should you have restrictions on using PHP on a site, or it not be a necessary solution to the problem.

  3. 3
    Arthur
    May 5, 2008 at 7:35 pm
    Permalink

    It is obvious, of course. I noticed one strange thing when you have a file1.php which includes include(’file2.php’) which in turn includes include(”file3.php’). Variables in file1.php are becoming invisible for file3.php and file2.php. Even if you global them. How actually to make them visible to all includes in all levels? Tried register globals on - also no success. Any comments?

  4. 4
    Arthur
    May 5, 2008 at 7:46 pm
    Permalink

    …but it works in mamp

  5. 5
    mog
    May 8, 2008 at 11:50 am
    Permalink

    Again, this is a PHP includes related question, …but as the include() function is simply add the contents of a given file into another it should not require any extra variable scope …but i would like to see your example, …i am back in the country now so you can come and see me to look at this.

  6. 6
    Arthur
    May 8, 2008 at 6:38 pm
    Permalink

    Sure. See you next week

Add Comment

Your email is never published nor shared. Required fields are marked *

*
*