How to redirect to another page using PHP

前端 未结 12 1397
粉色の甜心
粉色の甜心 2020-12-02 16:50

I am building a website which includes a login page. I need to redirect the user to their profile page once they\'ve logged in successfully, but I don\'t know how to do that

12条回答
  •  孤城傲影
    2020-12-02 17:47

    Assuming you're using cookies for login, just call it after your setcookie call -- after all, you must be calling that one before any output too.

    Anyway in general you could check for the presence of your form's submit button name at the beginning of the script, do your logic, and then output stuff:

    if(isset($_POST['mySubmit'])) {
        // the form was submitted
    
        // ...
        // perform your logic
    
        // redirect if login was successful
        header('Location: /somewhere');
    }
    
    // output your stuff here
    

提交回复
热议问题