2018-07-02 19:07
采纳率: 100%
浏览 24


I have a page where if you are logged in, you see your username and avatar. If you are not logged in, then you see a connect button that will redirect you to another page where you can enter your username and your password to log in.
What I want to do is after you log in and are redirected on the page you were before logging in.


if (isset($_POST["logIn"])) 

 } else
 {  ...}

What should I change to header?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doulierong0334
    doulierong0334 2018-07-02 19:21

    1- on login page, you need to get referrer url (from where it was redirected to login page that user not logged in)

    2- In that login form, make hidden field with that referrer value like:

    <input type="hidden" name="redirect" value="<?php echo $_SERVER['HTTP_REFERER'];?>">

    3- On submit, and verified username and password from database, redirect to this URL like

    header('location: '.$_POST['redirect']);
    点赞 评论
  • dounaidu0204
    dounaidu0204 2018-07-02 19:15

    You mean you just need to redirect to the referer url ? If so, try this :

    header('Location: ' . $_SERVER['HTTP_REFERER']);
    点赞 评论