What is wrong with my Php Code?

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
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

What is wrong with my Php Code?

Post by gaddyf »

I am trying to add three ip addresses so that if the ip's do not match the one i've entered, they will not see my webpage:

Code: Select all

 
<?php
// only local requests
if ($_SERVER['REMOTE_ADDR'] !== '99.54.88.685' '55.65.98.006' '64.99.78.136') die(header("Location: /"));
?>
 
using this, it does not work but using only one ip like below, it works. So how can i make it work on three or more ip's?

Code: Select all

 
<?php
// only local requests
if ($_SERVER['REMOTE_ADDR'] !== '99.54.88.685') die(header("Location: /"));
?>
Thanks
Last edited by Benjamin on Sun Aug 16, 2009 1:56 pm, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: What is wrong with my Php Code?

Post by jackpf »

You can't do that.
You need to do:

Code: Select all

if($_SERVER['REMOTE_ADDR'] == 'something' || $_SERVER['REMOTE_ADDR'] == 'something else')
Notice the || (or) symbol.
classi4u
Forum Newbie
Posts: 2
Joined: Sun Aug 16, 2009 12:38 pm

Re: What is wrong with my Php Code?

Post by classi4u »

Also use != instead of !==

Darsi
classi4u.com
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: What is wrong with my Php Code?

Post by jackpf »

It shouldn't make a difference since they're both strings.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: What is wrong with my Php Code?

Post by Benjamin »

:arrow: Moved to PHP - Code
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

Re: What is wrong with my Php Code?

Post by gaddyf »

jackpf wrote:It shouldn't make a difference since they're both strings.
Thank you for your help.
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

Re: What is wrong with my Php Code?

Post by gaddyf »

jackpf wrote:You can't do that.
You need to do:

Code: Select all

if($_SERVER['REMOTE_ADDR'] == 'something' || $_SERVER['REMOTE_ADDR'] == 'something else')
Notice the || (or) symbol.
Thank you man, it works.
Post Reply