Title: IP based redirect
Last modified: August 20, 2016

---

# IP based redirect

 *  [creativelifeform](https://wordpress.org/support/users/creativelifeform/)
 * (@creativelifeform)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/ip-based-redirect/)
 * 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?

Viewing 1 replies (of 1 total)

 *  Thread Starter [creativelifeform](https://wordpress.org/support/users/creativelifeform/)
 * (@creativelifeform)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/ip-based-redirect/#post-2288583)
 * 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
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘IP based redirect’ is closed to new replies.

## Tags

 * [IP](https://wordpress.org/support/topic-tag/ip/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [creativelifeform](https://wordpress.org/support/users/creativelifeform/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/ip-based-redirect/#post-2288583)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
