php-use the header() function-php

An HTTP (HyperText Transfer Protocol) header is used to send information back and forth between the server and the client (the Web browser). Normally this information is in the form of HTML, which is why the address for Web pages begins with http://.

But HTTP headers are a complicated enough subject to warrant a little more attention. There are actually dozens upon dozens of uses for HTTP headers, all of which you can take advantage of using PHP's header() function.. Here I'll demonstrate the most frequently used purpose—redirecting the user from one page to another—although the World Wide Web consortium's specifications on the subject are vast (Php header).

To redirect the user's browser with PHP, you would code:

header("Location: page.php");

You can also use the header function to send cookies, which is a good backup to the setcookie() function which sometimes has inconsistent results from one browser to the next.

header ("Set-cookie: name=value;
  expires=expiration");

The most important thing to understand about using header() is that it must be called before anything else is sent to the Web browser, just as you have to be careful when using the setcookie() function.

To demonstrate redirection, let's create a simple login script that sends a user to one page if they use the correct username and password or to another if they don't.

<?php

header ("Location: index.php");

exit;

?>