Redirect is a very powerful feature in PHP but if it is not implemented properly it can be very dangerous.

Generally, there are two ways to redirect in PHP


The most common redirect is using the header() function. This is a builtin PHP function that sends raw HTTP header to the client

The Syntex

header( $header, $replace, $http_response_code);

$header = This parameter represents header string

$replace = This parameter represents new header value

$http_response_code = This parameter represents HTTP response code.

The complete example will be


After the header, you should use exit or die. This is because bots and crawlers can ignore headers and they still can access the page that you want to protect using header redirect. So to stop processing you should append die() or exit() after you redirect.

Categorized in:

Tagged in: