10 PHP Header Examples

Page Header script was created to generate HTTP responses and HTML page headers, It renders HTTP response header for several purposes like force downloading files, avoiding page caching or adding any arbitrary headers.

1. Using PHP Headers to Force Download

This function allows us to define raw HTTP headers as a string. The script will then execute those headers and force the browser to render the page accordingly.
PHP-Headers-to-Force-Download-.jpg
Source


2. Including your HTML headers and footers in separate PHP files

The thing we don’t like about flat HTML files is you need to repeat the same HTML code throughout your website. There are ways around this such as using Dreamweaver templates but our preferred method is to move the common HTML code into separate files header.php and footer.php. See tutorial below.
Including-your-HTML-headers-and-footers-in-separate-PHP-files-.jpg
Source


3. PHP Headers Examples – 301,302, Redirects, 404, JavaScript, Download, Authentication dialog Headers

Headers list – Jump straight to:
301 moved permanently
302 moved temporarily
404 page not found
Service not available
CSS
JavaScript
Images(JPEG,BMP,PNG)
PDF
Force browsers not to cache pages
Download dialog
Authentication
php-headers.jpg
Source


4. PHP include() Function

The include() function takes all the content in a specified file and includes it in the current file.
PHP-include-Function-.jpg
Source


5. Avoiding: Headers already sent or cannot modify header information

This enabled you to call a header function anywhere on the page, the syntax to use is very simply at the very top of the file open PHP then type ob_start() this turns out output buffering.
Avoiding-Headers-already-sent-or-cannot-modify-header-information-.jpg
Source


6. PHP Header (Redirect Page)

You can redirect your user to some other page.
PHP-Header-Redirect-Page-.jpg
Source


7. PHP Header (Tell the browser to not cache some pages)

You can prevent the browser to cache pages by using the following code.
PHP-Header-Tell-the-browser-to-not-cache-some-pages-.jpg
Source


8. PHP Header (Send content types)

You can generate different types of data other than HTML, for example, you can parse an image, psd, zip etc from PHP.
PHP-Header-Send-content-types-.jpg
Source


9. PHP Header & Footer – Include

A simple tutorial that will show you how to use PHP to create a common header and footer file for your website, and how to use them properly.
php-header-and-footer.jpg
Source


10. Custom header tutorial: Adding an image and changing the size

In this tutorial we are going to go through how to add your own, customize the header to make it taller and change your text colour. For this tutorial we are using the Default BuddyPress 1.2 theme.
custom-header-tutorial.jpg
Source

One thought on “10 PHP Header Examples

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>