Page 1 of 1

What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 10:43 am
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

Re: What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 10:48 am
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.

Re: What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 12:43 pm
by classi4u
Also use != instead of !==

Darsi
classi4u.com

Re: What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 12:45 pm
by jackpf
It shouldn't make a difference since they're both strings.

Re: What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 1:56 pm
by Benjamin
:arrow: Moved to PHP - Code

Re: What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 2:50 pm
by gaddyf
jackpf wrote:It shouldn't make a difference since they're both strings.
Thank you for your help.

Re: What is wrong with my Php Code?

Posted: Sun Aug 16, 2009 2:51 pm
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.