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

前端 未结 4 674
一个人的身影
一个人的身影 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:30
    if($_SESSION['GOBACK']=='')
    {
      $_SESSION['GOBACK'] = $_SERVER['HTTP_REFERER'];
    }
    

    This seems to work. Thanks everyone.

    0 讨论(0)
  • 2021-01-21 23:33

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

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

    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.

    0 讨论(0)
  • 2021-01-21 23:38

    When they go to the page save the referrer in a session variable.

    After it refreshes and does the page logic, redirect to the session variable you saved.

    0 讨论(0)
  • 2021-01-21 23:41

    Store the referer in the first request into a session variable or a cookie. $_SESSION or $_COOKIE super globals can help achieve this.

    I recommend sessions as the user won't be able to hijack the value locally.

    0 讨论(0)
提交回复
热议问题