Page 1 of 2

Checking IP then redirecting

Posted: Fri Feb 20, 2004 4:36 pm
by popcop
how would i go about checkin a users ip address that is visiting my site... then by usng that ip address i would redirect them to another page

i know the ip address i want to redirect


i heard one simple php page would do this

Posted: Fri Feb 20, 2004 4:40 pm
by ol4pr0
is it just one ip adress ? or you want some security build in for youre webpage something like a abuse checker ?

Posted: Fri Feb 20, 2004 4:45 pm
by pickle
Look in the PHP Manual for the $_SERVER variables (used to be called $HTTP_SERVER_VARS). I believe something like what you're looking for can be found there.

Posted: Fri Feb 20, 2004 4:47 pm
by vigge89

Code: Select all

<?php

$visitors_ip = $_SERVER['remote_addr'];

echo "Your ip is: $visitors_ip";

?>

Posted: Fri Feb 20, 2004 4:50 pm
by tim

Code: Select all

<?php
$ip = 127.0.0.1;
if($REMOTE_ADDR == $ip) {
//DIRECT TO PAGE WHATEVER
} else {
//whatever u want to do if the IP is not the same
}
?>

Posted: Fri Feb 20, 2004 5:59 pm
by popcop
i know the ip address im wanting to redirect

i just want to sent that specific ip address to an diffrent page

Posted: Fri Feb 20, 2004 6:15 pm
by redhair

Code: Select all

<?php
   $ip_visit = getenv("REMOTE_ADDR"); 


   $ip_array[] = "127.0.0.1"; //popcup
   $ip_array[] = "216.239.59.104"; //your friend

   foreach ($ip_array as $ip_match) 
   { 
      if (preg_match("/$ip_visit/","$ip_match")) 

      { 
       header ("location:http://www.php.net");
      } 
   }
?>
Posted a very simular post here,... like a day ago. As a give away on "Code Snippets" forum.

Posted: Fri Feb 20, 2004 7:00 pm
by popcop
i tried that code there and it doesnt seem to be working

Posted: Fri Feb 20, 2004 7:02 pm
by redhair
popcop wrote:i try that code there and it doesnt seem to be working
Why not?

Posted: Fri Feb 20, 2004 7:05 pm
by popcop
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#FFFF99" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<?php
$ip_visit = getenv("REMOTE_ADDR");


$ip_array[] = "62.252.128.12 "; //popcup


foreach ($ip_array as $ip_match)
{
if (preg_match("/$ip_visit/","$ip_match"))

{
header ("location:http://www.php.net");
}
}
?>


<table width="75" height="78" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>

Posted: Fri Feb 20, 2004 7:11 pm
by dethron
Popcop, the problem has beed solved, hasn't it?

Posted: Fri Feb 20, 2004 7:12 pm
by popcop
thats the code im using in my php file but it doesnt seem to be redirecting

Posted: Fri Feb 20, 2004 7:13 pm
by popcop
dethron wrote:Popcop, the problem has beed solved, hasn't it?
nope... its no redirecting

Posted: Fri Feb 20, 2004 7:14 pm
by dethron
The following is a part of some code that i wrote.

Code: Select all

<?php
		}
		else if($ID == 13) 
		echo "<script>location.replace("/forum/index.php")</script>";
		
		else if($ID == 43){
		echo "<script>location.replace("/sponsor/")</script>";
		}
		
		else {
			echo "<a href=indexm.php class=forumlink>Beklenmeyen komut seçimi!!!</a>";
		}
?>
Make use of it ;)

Posted: Fri Feb 20, 2004 7:16 pm
by popcop
aaargggghhhh..... i cant get this to work