How to Redirect to Another Page When Session Timeout in PHP

How to Redirect to Another Page When Session Timeout in PHP thumbnail
PHP redirects are an easy way to send a vistor to another web page after a specified period of time.

Redirects allow a web page to automatically send a visitor to another page after a specified period of time. This is very useful for pages containing sensitive data, as the page can be cleared and directed to a logout screen if the user walks away from the computer. When a Web page contains a redirect, it automatically counts down any time the page is loaded. The redirect then executes when the timer reaches zero.

Instructions

    • 1

      Remove any HTML header tags that may be in your document. This would be any information included in a <HEAD> section of code. Header information will be replaced by the PHP code you entered.

    • 2

      Insert the following snippet of code at the beginning of the PHP document:

      header( 'refresh: 0; URL=http://www.example.net' );

      Replace the zero with the number of seconds before the page times out, then replace the URL with the page you wish to redirect to when the page times out.

    • 3

      Save the PHP document and load the Web page to ensure the redirect follows to a valid page.

Tips & Warnings

  • Setting the refresh value to 0 will redirect the user to another web page as soon as it is opened.

  • Do not set the page to redirect to itself on timeout. This will create an infinite reloading loop.

Related Searches:

References

  • Photo Credit Comstock/Comstock/Getty Images

Comments

Related Ads

Featured