Forums

IP based redirect (2 posts)

  1. creativelifeform
    Member
    Posted 1 year ago #

    Hi all, I wrote this redirect function which sort of works

    function underConstruction()
    {
        $visitor = $_SERVER['REMOTE_ADDR'];
        $valid_ips = array("1","2","3","4");
    
        if(!in_array($visitor, $valid_ips))
        {
            header("Location: http://www.redirecthere.com");
        }
    }

    I've removed the IP addresses. Now this...kind of works. It works if I try to access any other page of the site other than the home page from a non valid IP. When accessing the home page, I get an error stating that the headers cannot be modified as they've already been sent. Anyone else ever had this issue?

  2. creativelifeform
    Member
    Posted 1 year ago #

    Okay have modified the code to use Javascript redirection (eventhough I think that is lame), just replace the header function with this

    ?>
            <script type="text/javascript">window.location = "http://www.redirecthere.com"</script>
            <?php

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags