Redirecting the User in PHP

Redirecting the User in PHP
PHP redirect mechanism is used to navigate the user from one page to another without clicking any hyperlinks. 
It should be done in the background. 

For example, in the payment gateway, the redirect should automatically be taken place to notify the URL using PHP script.

PHP provides predefined function, named header(),for URL redirection. 
Using this header() function, send location header by specifying the URL to which the page should be redirected.

Note: Before specifying the page URL for the location header, we should make sure that the page exists.

Redirection from one page to another in PHP is commonly achieved using the header function:

Using Header Function in PHP:
The header() function is an inbuilt function in PHP that is used to send the raw HTTP (HyperText Transfer Protocol) header to the client.
Syntax:
header( $header,)

Parameters: T
$header: to hold the header string.

<?php 
  // Redirect browser 
header("Location: http://www.drpankajdadhich.com"); 
  exit(); 
?> 

Note: The die() or exit() function after header is mandatory. If die() or exit() is not put after the header(‘Location: ….’) then the script may continue resulting in unexpected behavior. 

Usability:-  
  • Collecting data on your visitors without you being aware of it.
  • Using web analytics software to track the performance of your site. 

In our post-GDPR world, that could have significant consequences.

Be careful with PHP redirects, use them properly and only use them where and when you absolutely have to.

=================================================

Post a Comment

0 Comments