how do i add another IP to this ????
Moderator: General Moderators
how do i add another IP to this ????
im using this code to redirect my friend to another page when he visits my site
<?php
$ip = "213.78.27.203";
if($REMOTE_ADDR == $ip) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>
how would i add another ip address to it.... if i wanted to redirect another friend
would it be :
<?php
$ip = "213.78.27.203";
$ip = "203.20.6.78";
if($REMOTE_ADDR == $ip) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>
<?php
$ip = "213.78.27.203";
if($REMOTE_ADDR == $ip) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>
how would i add another ip address to it.... if i wanted to redirect another friend
would it be :
<?php
$ip = "213.78.27.203";
$ip = "203.20.6.78";
if($REMOTE_ADDR == $ip) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>
I would go for:
<?php
$ip = "213.78.27.203";
$ip2 = "203.20.6.78";
if($REMOTE_ADDR == $ip or $ip2) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>
<?php
$ip = "213.78.27.203";
$ip2 = "203.20.6.78";
if($REMOTE_ADDR == $ip or $ip2) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>
Code: Select all
<?php
$ip = "213.78.27.203";
$ip2 = "203.20.6.78";
$ip3 = "YOUR IP HERE"
if($REMOTE_ADDR == $ip or $ip2 or $ip3) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}
?>Code: Select all
$_ips=array(
"213.78.27.203",
"203.20.6.78"
//more ips could be added
)
if(in_array($_SERVER["REMOTE_ADDR"],$_ips)){
// redirect
}gangboy:
You can't do this (your if syntax is incorrect
has to be like this..
but, would be even better to do it like this...
Mark
Mark
You can't do this (your if syntax is incorrect
Code: Select all
$ip = "213.78.27.203";
$ip2 = "203.20.6.78";
$ip3 = "YOUR IP HERE"
if($REMOTE_ADDR == $ip or $ip2 or $ip3) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}Code: Select all
$ip = "213.78.27.203";
$ip2 = "203.20.6.78";
$ip3 = "YOUR IP HERE"
if($REMOTE_ADDR == $ip || $REMOTE_ADDR == $ip2 || $REMOTE_ADDR == $ip3) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}Code: Select all
$ips = array("213.78.27.203",
"203.20.6.78",
"YOUR IP HERE"); //Just keep adding as many as you want
if (in_array($REMOTE_ADDR, $ips)) {
echo "<script language=javascript>location.replace('http://www.yahoo.com)</script>";
}Mark
I would go like weirdan said.Weirdan wrote:Code: Select all
$_ips=array( "213.78.27.203", "203.20.6.78" //more ips could be added ) if(in_array($_SERVER["REMOTE_ADDR"],$_ips)){ // redirect }
Its easyer to insert or delete a ip on a later stage when the list is getting
bigger along the way
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
AbelaJohnB
- Forum Newbie
- Posts: 9
- Joined: Sat Feb 28, 2004 12:14 am
This instance really calls for the usage of an [php_man]array()[/php_man], I feel.
Perhaps this would be better:
Perhaps this would be better:
Code: Select all
<?php
//
// let's grab the users ip address
// should catch everything, except for some transparent proxies.
//
if( getenv('HTTP_X_FORWARDED_FOR') != '' )
{
$users_ip_address = ( !empty($HTTP_SERVER_VARSї'REMOTE_ADDR']) ) ? $HTTP_SERVER_VARSї'REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARSї'REMOTE_ADDR']) ) ? $HTTP_ENV_VARSї'REMOTE_ADDR'] : $REMOTE_ADDR );
if ( preg_match("/^(ї0-9]+\.ї0-9]+\.ї0-9]+\.ї0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip_list) )
{
$private_ip = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.16\..*/', '/^10..*/', '/^224..*/', '/^240..*/');
$users_ip_address = preg_replace($private_ip, $users_ip_address, $ip_listї1]);
}
}
else
{
$users_ip_address = ( !empty($HTTP_SERVER_VARSї'REMOTE_ADDR']) ) ? $HTTP_SERVER_VARSї'REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARSї'REMOTE_ADDR']) ) ? $HTTP_ENV_VARSї'REMOTE_ADDR'] : $REMOTE_ADDR );
}
//
// let's make this a bit easier to detect the true/recurring ip...
//
$$users_ip_address_block = substr($users_ip_address, 0, 10);
//
// build a list of ip's we would like to ban/redirect
//
$go_bye_bye = array('208.25.194', '63.160.62.', '63.160.62.128', '206.14.153'); // , '127.0.0.1'
//
// now we do a compare of "in_array".... if something is in something, do something
//
if (in_array($$users_ip_address_block,$go_bye_bye))
{
//
// build our redirect link... down with javascript!
// than throw a header for google.... <sigh>
// than throw a header for the true redirect
// than throw a die() to force page-death with a nice little message.
//
$temp_url = 'http://www.yahoo.com/';
header('HTTP/1.1 301 Moved Permanently');
header("Location: ". $temp_url);
exit('<BR />Redirecting: <BR />' . $temp_url);
}
//
// That's All Folks
//
?>-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
What about a partial IP, like the first 3 letters? Don't those stay pretty static? The only prob I can see is someone else with the same first 3 digits of their IP the same as the friend, and they get offended or somethin'.Illusionist wrote:ya, Like Steve said, it'd kind of hard to play a trick onsomeone liek that unless they have a static IP address...
Code: Select all
<?php
$ip=getenv("REMOTE_ADDR");
if("127"==substr("$ip", 0, 3)){
//Don't do anything
}else{
//redirect
";
?>