How do I save the original $_SERVER['HTTP_REFERER']; on a page that refreshes several times?

前端 未结 4 759
一个人的身影
一个人的身影 2021-01-21 22:58

I have a page where I need to get the referring URL so I can redirect them back after they compete a form. My problem is, the form has several drop menus and each time a selecti

4条回答
  •  情深已故
    2021-01-21 23:33

    If you insist on doing it with forms and hidden inputs, that's easy.

    
    

    You could also do it with sessions, though, supposing you use session_start().

    session_start();// At the very top of your page. Literally THE TOP.
    
    // Set our session variable only if it is not currently set. 
    if (!isset($_SESSION['referrer'])) {
        $_SESSION['referrer'] = $_SERVER['HTTP_REFERER'];
    }
    

    For more on sessions, see this. Sessions were meant for just this sort of thing, taking variables across pages and preserving state.

提交回复
热议问题