This article is a Snippet about how to redirect from one page to another page in PHP after a few seconds. In this article, I’m going to show you,
- Â How to redirect the pages in PHP without setting time.
- Â How to redirect the pages in PHP with setting the time.
Before starting the coding, let me explain the theme setup, First I’m going to consider the two PHP pages in one folder.
- loginpage.php
- homepage.php
In loginpage.php page, add the form input fields with username, password and submit button and style it. whenever a user tries to login, first it validates the form and next if form values are set it redirects to the homepage.php.
This is how the login page looks after styling it.
Note: I’m using the local server wamp for this demo. and I’m not going to explain about HTML and CSS in this article.
How to redirect the pages in PHP without setting time.
PHP code:
code explanation:
whenever a user submits the login button, submitted value sets into a isset()
function and next if a user enters the login credentials then if-else statement checks, whether the form values are set or not, if form values are set it redirects to the homepage.php and if form values are not set it shows the error message.
whenever login credentials are not set, then the user gets an error message.
How to redirect the pages in PHP with setting the time.
PHP code:
code explanation:
whenever a user submits the login button, submitted value sets into a isset()
function and next if a user enters the login credentials then if-else statement checks, whether form values are set or not, if form values are set it shows the success message then after 3 seconds it redirects to the homepage.php and if form values are not set it shows the error message.
Redirecting code without time set:
header('location:URL ADDRESS');
Redirecting code with three seconds time set:
header('refresh:3; url=URL ADDRESS');
- CSS Speech bubbles - July 20, 2020
- Simple Button Hover effect – Border Hover effect - October 9, 2017
- Glowing Social icons hover effect - September 11, 2017
You need to set a HTTP 301 or 301 status code as well. Just setting the Location header isn’t enough.
I’m done