A
A
Andrey Raboy2015-10-16 21:02:05
PHP
Andrey Raboy, 2015-10-16 21:02:05

Is the redirect implemented correctly depending on the client's IP?

Good time, you need to redirect the client depending on which IP he came from. The script works, but are there any comments or additions?
The point is to redirect clients from the external network and internal to different addresses. Like, if you are from the inside - you are on mysite.com, and if you are from the outside - you are on mysite2.com.
There are about 150 clients in the internal network, so we are looking for IP 192.168.1.*

<?php
// сохраняем адрес клиента
$remote_addr = $_SERVER['REMOTE_ADDR'];
// часть адреса сети
$local_ip = '192.168.1';
// определяем вхождение подстроки в строку, позиция не важна
$x = strpos($remote_addr, $local_ip);
// формируем переменную $redirect в зависимости от IP клиента 
if ($x===false){ $redirect="http://mysite.com";}
else { $redirect="http://192.168.0.11";}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>Перенаправление...</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  <meta name="description" content="Перенаправление..."> 
 <meta http-equiv="refresh" content="3; URL=<?php echo $redirect?>">
 </head> 
 <body> 
  <p>Сейчас вы будете перенаправлены по адресу: <?php echo $redirect?> </p>
 </body>
</html>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2015-10-16
@dimonchik2013

serious guys send header from 301 302m

E
Everal, 2015-10-16
@Everal

if($remote_addr != $local_ip){
 $redirect="http://192.168.0.11";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question