See the new scripts recently added to Dynamic Drive. Click here.
Original, practical CSS codes and examples such as CSS menus for your site.
-->
    Search code samples  
 
  Keyword
 
 
 
   
 
 
  Code Samples
 
ASP
CSS
Dhtml
Html
Javascript
PHP
 
   
     LOGIN HERE  
 
Username
Password
Forgot Password
Verify Signup
 
 
 

PHP >> General

what is Header in PHP?

Visitor Ratings (25) :

Description
The following steps should teach you everything you need to know about php headers.

1. The http header allows you to send many messages to the browser, the first of these that I'll explain is the location header.

<?php
header("Location: http://itechies.net");
?>

2. This will send a new location to the browser and it will immediately redirect. It's recommended to put a full url there, however almost all browsers support relative urls.
3. You can also control the content type that the browser will treat the document as:

<?php
header("Content-Type: text/css");
?>

4.You can now link to this file as css.php in your link to your css and dynamically create your css document depending on what browser or resolution the viewer has. This can be really helpful when designing css that works in every browser.
5. You can also force the browser to display the download prompt and have a recommended filename for the download.

<?php
header("Content-Type: image/jpeg");
header("Content-Disposition: attachment; filename=file.jpg");
?>

6.This will not show the file as it usually would in a browser, but as I mentioned before, display the downloads prompt and the filename will automatically be set to file.jpg regardless the filename of the php file. You can also force the page to be displayed inline by changing the content-disposition from attachment to inline.
7. You can also send specific errors to the browser using the header function. It's important to remember the different error messages and what they mean.

<?php
header("HTTP/1.0 404 Not Found");
?>

8. Finally, I'd like to suggest that immediately following using a header, you use exit to make sure none of the code after it is executed (unless of course that code is used to make an image or needed in the file):

<?php
header("Location: http://www.example.com/");
exit;
?>
Code
Select All
 Rate this Resource
Related Links:
PageRank




Earn revenue from 
your website's traffic.






Reliable hosting for $6.95!

FreeLance Jobs from ODesk!



 
Home    Blog    Ajax    CSS    Hot scripts    Tips & Tricks    Webmaster Resources     Freelance jobs    Articles    Sitemap    Website builder and Cheap domain names    Lotus Notes FAQ    Our partners