Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting in a PHP page to another PHP page

Tags:

php

I have a register.php, login.php, and main.php. How do i redirect user after after registration submit to login page and then login page submit to main page.

like image 957
Ethan Avatar asked Jan 22 '23 04:01

Ethan


1 Answers

header("Location: /login.php");
exit; 

See the exit. Don't ever forget to do this. If you have sensitive data after this, it will be visible to anyone that doesn't follow location headers (such as some bots).

To stop you from forgetting, you could build a wrapper type function

function redirect($url) {
    header('Location: ' . $url);
    exit;
}
like image 179
alex Avatar answered Feb 01 '23 13:02

alex