Checking IP then redirecting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Checking IP then redirecting

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

is it just one ip adress ? or you want some security build in for youre webpage something like a abuse checker ?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Code: Select all

<?php

$visitors_ip = $_SERVER['remote_addr'];

echo "Your ip is: $visitors_ip";

?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
}
?>
popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Post by popcop »

i know the ip address im wanting to redirect

i just want to sent that specific ip address to an diffrent page
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post 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.
popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Post by popcop »

i tried that code there and it doesnt seem to be working
Last edited by popcop on Fri Feb 20, 2004 7:05 pm, edited 1 time in total.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

popcop wrote:i try that code there and it doesnt seem to be working
Why not?
popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Post 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>
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Popcop, the problem has beed solved, hasn't it?
popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Post by popcop »

thats the code im using in my php file but it doesnt seem to be redirecting
popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Post by popcop »

dethron wrote:Popcop, the problem has beed solved, hasn't it?
nope... its no redirecting
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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 ;)
popcop
Forum Newbie
Posts: 21
Joined: Fri Jan 30, 2004 10:42 am

Post by popcop »

aaargggghhhh..... i cant get this to work
Post Reply