Please help me to create simple if and else php script

Status
Not open for further replies.

linux1880

In Runtime
Messages
455
I want the simple php script which would determine

if your IP address if 10.0.0.2 goto this url

else go to this url


How do I do that please help me.

Thank you
 
PHP:
<?php

if ($_SERVER['REMOTE_ADDR'] == '10.0.0.2') {
// if the ip is 10.0.0.2 go here:
header ('location: http://url.com');
} else {
// otherwise go here:
header ('location: http://url.com');
}

?>
 
CrazeD's most likely works as well but just if anyone was wondering, i get mine using:

PHP:
$ip = getenv("REMOTE_ADDR") ;
 
See I have 100% success on any server with this

PHP:
if (getenv(HTTP_X_FORWARDED_FOR)) {
    $ip = getenv(HTTP_X_FORWARDED_FOR);
	}else{
    $ip = getenv(REMOTE_ADDR);
	}

so to turn this into what is needed...

PHP:
if (getenv(HTTP_X_FORWARDED_FOR)) {
    $ip = getenv(HTTP_X_FORWARDED_FOR);
	}else{
    $ip = getenv(REMOTE_ADDR);
	}
if ($ip == '10.0.0.2'){
     header('location: http://www.url1.com/index.php');
     exit();
     }else{
     header('location: http://www.url2.com/index.php');
     exit();
     }

I like the exit(); to make sure it doesn't run any more of the script even after it supposedly redirects.
 
Status
Not open for further replies.
Back
Top Bottom