if then header problem

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

Post Reply
bobby9101
Forum Commoner
Posts: 28
Joined: Thu Apr 27, 2006 1:18 pm

if then header problem

Post by bobby9101 »

I would like to use an if then statement for two header locations.
say i access page hello.php from my ip address 127.0.0.1 then i get sent to index.php
but if i access from any other ip i get sent to goodbye.php

i set them as variables like this:

Code: Select all

$header = 'if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') header("Location: hello.php");';
$header2 = 'header("Location: goodbye.php");';
any ideas on how to make this work?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

on the right track you are:

try this you should:

Code: Select all

if($_SERVER['REMOTE_ADDR'] == "127.0.0.1")
{
   header("Location: hello.php");
   exit;
}
else
{
   header("Location: goodbye.php");
   exit;
}
bobby9101
Forum Commoner
Posts: 28
Joined: Thu Apr 27, 2006 1:18 pm

Post by bobby9101 »

THANK YOU
i am a total newbie i am suprised i got that far
could have never done it without you
Post Reply