PHP

PHP : Redirect user back to LoggedIn page after logging in

  • php
  • session
  • redirect
  • header

3 comments

Ng WJ
4 years ago

Thanks for guidance, posting my code as an example.

So we reuse isSubmit below like that after setting to true upon button submit. 
       $_SESSION["isSubmit"] = true;

Ng WJ
4 years ago

session_start();
if (isset($_SESSION['isSubmit'])) { # Check if user has already submit form, and redirect back to output.php if already logged in
    header("Location: " . SITE_URL . "output.php");
    exit();
}

Hi Victor,

Can you show me what your code is like in screenshot or in text so I can further assist from there?

Session is exactly the same concept as cookies. Just that you have to remember to start_session(); before doing it. And once browser is closed session is always cleared. So if once the user close the browser, they should end up back to login page if they go back to the webpage.