Redirect via .htaccess

Discussion in 'PHP' started by qwikad.com, Jul 21, 2024.

  1. #1
    So right now I'm redirecting like so:

    if ($login == "Success") {
     
    echo '<script>location.href = "user_account.php";</script>';
    
    }else{
    
    $err = "some error";
    
    }
    Code (markup):
    It's sluggish. Takes a couple seconds. I did an html redirect via the header, same thing - sluggish.

    I'd like redirect from login.php (once a user is logged in) to user_account.php via .htaccess. How do I do that? I know how to do a redirect from one file to another, but how do I do the same only after a successful login?


    .
     
    qwikad.com, Jul 21, 2024 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,789
    Likes Received:
    4,528
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Your logic should be at the top of the script before you output anything which means you can use header()
    ref: https://www.php.net/manual/en/function.header.php

    if ($login == "Success") {
       header('Location: https://mysite.com/user_account.php');
       exit;
    } else {
       $err = "some error";
    }
    PHP:
     
    sarahk, Jul 21, 2024 IP
    qwikad.com likes this.