PHP redirect based on IP AND referrer

前端 未结 1 819
耶瑟儿~
耶瑟儿~ 2021-01-27 17:52

I\'m trying to redirect users within my network to a specific landing page on our website based on their IP and a blank referrer. This code works, but it ends up in a redirect l

相关标签:
1条回答
  • 2021-01-27 18:49

    Add a session to that user that you know that they were redirected already:

    session_start();
    $visitor = $_SERVER['HTTP_REFERER'];
    $clientip = $_SERVER['REMOTE_ADDR'];
    $ip = a regex list of IPs;
    if (empty($visitor))
    {
    
        //add on if they did not redirect yet.
        if (preg_match($ip, $clientip) && 
            (!isset($_SESSION['redirect']) || !$_SESSION['redirect'])) {
            $_SESSION['redirect'] = true;
            header('Location: http://example.com');
            die();
        } 
    
    }
    
    0 讨论(0)
提交回复
热议问题