Networking, Programming and Graphics - Tutorials
ONLINEHOWTO.net Tutorials Category

Send header to browser with PHP

Type: Code Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Level: Beginner Networking, Programming and Graphics - Tutorials 
Networking, Programming and Graphics - Tutorials
Date: 2007-Mar-12
Networking, Programming and Graphics - Tutorials
Visited: 5725 times
Networking, Programming and Graphics - Tutorials
Rating: Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Published: Ivory Morhuld

This tutorial will show you how to send header to the browser with PHP.

Headers is the first part of http communication which receive client web browser. To send header use:
<?php
header
("your heaader code: goes here");
?>
If you want to send header for redirecting the browser use this:
<?php
header
("Location: http://www.onlinehowto.net");
?>
For sending 'missing page' header try this:
<?php
header
("HTTP/1.0 404 Not Found");
?>
PHP scripts often generate dynamic content that must not be cached by the client browser or any proxy caches between the server and the client browser. Many proxies and clients can be forced to disable caching with:
<?php
header
("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?> 
If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.
<?php
header
('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="document.pdf"');
readfile('document.pdf');
?> 
To send authentication dialog to user use this code:
<?php
header
("WWW-Authenticate: NTLM");
?> 
Rate this tutorial:                    
Post Comment

    • ( yourfeedbackemail [ at ] gmail . com ),

      posted on 2010-Apr-10 | 06:25:41 AM
      Is there any explanation about Pragma headers?
Need a specific tutorial? Do not hesitate and submit a request!
Your e-mail: