Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 4 days ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 1 week ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Using PHP includes

AshleyAshley

PHP is a powerful language that has replaced HTML frames and JavaScript includes in performing the task of including code from one page onto another. Generally PHP includes are used for database connection scripts, functions or classes, to be included in dynamic pages. But they can also be used in your static html projects too.

This is really useful for including anything from a header, footer, menu or a script across multiple pages. If you then need to make a change to the header, footer, menu or script, then you only need to edit the included file.

How to use it

Its really simple to get started with includes. If you want to include a menu in your web project simply add the line of code below to your site pages.



You then need to create the includes folder on your server and paste the following code or what ever script you want.

When you create the menu.php page there is no need to have the html doc type head and body script in there just your menu code, this is because php will include the complete file ‘as is’ and you will have two head and body tags.


Home /
About Us /
Links /
Contact Us

So includes can be a great time saver when creating generic content throughout a site, this has been a simple introduction on how to get started using them.

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 4
  • dcypher.co.uk
    Posted on

    dcypher.co.uk dcypher.co.uk

    Reply Author

    includes saves so much time updating your sites, I use then whenever poss.


  • Nick
    Posted on

    Nick Nick

    Reply Author

    Isn’t it better to use require on db connects and that sort of thing?


    • Ashley
      Posted on

      Ashley Ashley

      Reply Author

      @nick The two functions are identical in every way, except how they handle errors. The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).


  • Brian
    Posted on

    Brian Brian

    Reply Author

    Wow, awesome, I have been using iframes! Much simpler lol