Author

TheDesignJunkie.com is the blog of Cole Hicks. Cole is a web designer, consultant, and computer book author covering topics related to graphic design, the web, and web 2.0 technology.

Newsletter

    Weekly newsletter packed full of the latest web design tips, tutorials. It's free to subscribe and you can opt-out at any time.

PHP Tutorial 10 | Using External File Includes

5 November 2007 - 3:57

Now that you know the basics of PHP we can begin the process of creating an actual website! If you have much experience with HTML you may have heard of Server Side Includes (SSI). Essentially server side includes are a way to create headers, footers, scripting statements, or other elements that can be reused (or included) on multiple pages.

In PHP there are four functions that you can use to call external files and include them in your page. Those are:

include()
include_once()
require()
require_once()

Using Include()

As you can imagine, include() includes an external file in your php script. To demonstrate how this works imagine we have three files.

The first is a header.inc file which contains a basic h1 header for the page:

<h1>Using External File Includes</h1>

The second a footer.inc file containing a paragraph of contact information:

<p>contact us at info@thedesignjunkie.com</p>

You can imagine where we are going with this ;-)

Now, in our PHP file (page1.php) we want to include the header and the footer files. The page code would look something like this:

<html>
<head>
</head>
<body>
     <?php
         include 'header.inc';
     ?>

     <?php
        include 'footer.inc';
     ?>
</body>
</html>

Load all three files to the same directory and call up the PHP page in your web browser and you get:
Include Function

Looking at the source code or the document you’ll notice that you don’t see any PHP script. All you see is the HTML code.

Using Require()

Require() behaves just like include() except if for some reason the file requested does not load the require() function will kill the entire script and you will get an error message. Using include() you don’t get this. For this reason I suggest using include() for cosmetic includes and require() when you have an include that is more important. Essentially, you should use require when you want the entire script to stop if the include is not found.

Include_Once() and Require_Once()

Just like include() and require(), the include_once() and require_once() functions are used to include headers, footers, scripting statements, or other elements that can be reused (or included) on multiple pages. The only difference is that with the ending _once() the functions are only called one time.

[ Go back to PHP Tutorial 11 | Working with Forms in PHP ]

[ Go back to PHP Tutorial 9 | For and While Loops in PHP ]

No Comments | Tags: PHP, Uncategorized

Designing with Type: What is a type conflict?

25 October 2007 - 3:30

I’ll never understand why so many designers get this wrong. It seems like a fairly simple concept. In typography, particularly within a paragraph, as a general rule you either want the same font or something which contrasts well otherwise you have a typographic design conflict. A conflict in typography, is when two or more typefaces on the same page, within the same paragraph, or even in the same sentence are simply too similar. Here is an example:

Example of Conflict

Notice how the words “too similar to one another” are in a different font. Glancing at them they just don’t look right. If they had more contrast they would be okay because you wouldn’t expect them to look like each other. But given that the font’s look so similar, in your mind (or at least in mine), you want them to be the same font.

No Comments | Tags: Principles of Design, Uncategorized