Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Please help me to create simple if and else php script
Closed Thread
Old 07-31-2008, 08:45 AM   #1 (permalink)
 
Super Techie

Join Date: Feb 2004

Posts: 442

linux1880 is on a distinguished road

Send a message via Yahoo to linux1880
Default Please help me to create simple if and else php script

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
linux1880 is offline  
Old 07-31-2008, 10:12 PM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Please help me to create simple if and else php script

PHP Code:
<?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');
}

?>

__________________

Need website help? PM me!
CrazeD is offline  
Old 08-03-2008, 01:05 AM   #3 (permalink)
zedman3d's Avatar
 
I am of the highest lvl..

Join Date: Oct 2007

Location: Sydney, Australia

Posts: 2,454

zedman3d will become famous soon enoughzedman3d will become famous soon enough

Default Re: Please help me to create simple if and else php script

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

PHP Code:
$ip getenv("REMOTE_ADDR") ; 

__________________



My pick up line is: I know Vernong.

Trotter: "Ask all the questions you want... whatever we don't know, we'll make
up something that sounds pretty good."

Antec-User: "I have a display now, but the darn system is crash-bandicoot on stock"
zedman3d is offline  
Old 08-07-2008, 12:42 AM   #4 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default Re: Please help me to create simple if and else php script

See I have 100% success on any server with this

PHP Code:
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 Code:
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.
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On