PHP Redirect help

by 8 replies
10
Hey guys,

I was given this code by a fellow member but I didn't want to bother him again so I was wondering if anybody else knew.

<?php

$ip_address = $_SERVER['REMOTE_ADDR'];

if ($ip_address == '108.7.3.52')
header("Location: http://myurl.com/http://page.html");
else
header("Location: http://myurl.com/page2.html");

?>

I was wondering if anybody knows the function for an array (more than 1 ip).

Thank you in advance!

D
#programming #php #redirect
  • $ipaddresses = array('108.7.3.52','108.7.3.53','108.7.3.54');

    if (in_array($_SERVER['REMOTE_ADDR'],$ipaddresses]))
    {
    header("Location: http://myurl.com/http://page.html");
    } else {
    header("Location: http://myurl.com/page2.html");
    }
    • [ 1 ] Thanks
    • [1] reply
    • Thank you lisa!!
      • [1] reply
  • To make sure that the code will work, Put it at the first line.
    • [1] reply
    • Remove the final square bracket after $ipaddresses on the if... line i.e. change:

      if (in_array($_SERVER['REMOTE_ADDR'],$ipaddresses]))

      to:

      if (in_array($_SERVER['REMOTE_ADDR'],$ipaddresses))
      • [ 1 ] Thanks

Next Topics on Trending Feed

  • 10

    Hey guys, I was given this code by a fellow member but I didn't want to bother him again so I was wondering if anybody else knew.