PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 20th, 2013, 06:09 PM
ukndoit ukndoit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 39 ukndoit Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 12 h 16 m 18 sec
Reputation Power: 0
Simple IP address check problem

Ok, I am working on a page, I put my IP address in a string, then I have the code check the IP address of the visitor to see if the IP address is the same as mine that I hard coded so I can test things.

The problem is, that it fails every time. I am not sure it's because of the periods in the ip address or what... here is the code:

PHP Code:
if($_ENV['REMOTE_ADDR'] == "$_compIp") {
  echo 
"True";
} else {
  echo 
"False";



that prints False, but when I have it print the both the IP addresses they are the same in the string:

PHP Code:
echo "'" $_ENV['REMOTE_ADDR'] . "'<br>";
echo 
"'" $_compIp "'"


that outputs: the same ip address in both quote marks, so it should be the same so the == should be TRUE.

I also tried this:
PHP Code:
 $cmp strcmp($_ENV['REMOTE_ADDR'], $_compIp);
if(
$cmp 1) {
 echo 
"Compare passed";
} else {
echo 
"Compare failed";



that prints the failed message every time. So even the compare is not working.

since
PHP Code:
 $_ENV['REMOTE_ADDR'
contains the ip address and it matches the one I hard coded to
PHP Code:
 $_compIp 
I don't know why it is not working.

any idea how to make this work? I only need it while I am testing...

Thank you for your help if you can provide it.
Rich

Reply With Quote
  #2  
Old February 20th, 2013, 06:26 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
PHP Code:
echo $_SERVER['REMOTE_ADDR']; 


that's your ip (see the manual )


p.s notice the difference when testing it locally and on a live server
__________________
PHP Tutorial

Last edited by aeternus : February 20th, 2013 at 06:30 PM.

Reply With Quote
  #3  
Old February 20th, 2013, 06:43 PM
ukndoit ukndoit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 39 ukndoit Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 12 h 16 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by aeternus
PHP Code:
echo $_SERVER['REMOTE_ADDR']; 


that's your ip (see the manual )


p.s notice the difference when testing it locally and on a live server


thank you for your reply, I changed it and it still did not work:

PHP Code:
if($_SERVER['REMOTE_ADDR'] == "$_compIp") {
echo 
"True!!";
} else {
echo 
"Still False!";



output: Still False!

even though the IP address I echo above it in the Server remote addr is the same one In the string I am comparing.

Maybe I should explode the ip addresses into two arrays and check each sector against each other... individually, that is overkill, but it may work since this is not.

I am testing these on a live server, Unix Server running latest Apache and Php 5.x

any idea why it still is not working?

Thx again,
Rich

Reply With Quote
  #4  
Old February 20th, 2013, 06:48 PM
Aurum84 Aurum84 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 74 Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level)Aurum84 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 23 h 5 m 49 sec
Reputation Power: 17
Remove the quotes around $_compIp ?

Reply With Quote
  #5  
Old February 20th, 2013, 06:50 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
as (implicitly) suggested you first echo out $_SERVER['REMOTE_ADDR']
Than you know exactly what value it has. Compare that to your hardcoded value.
Echo them both so you know exactly what is going on

Reply With Quote
  #6  
Old February 20th, 2013, 06:50 PM
ukndoit ukndoit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 39 ukndoit Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 12 h 16 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by Aurum84
Remove the quotes around $_compIp ?


done.... still false

crazy

Rich

Reply With Quote
  #7  
Old February 20th, 2013, 06:52 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
notice my post...
Quote:
Originally Posted by aeternus
as (implicitly) suggested you first echo out $_SERVER['REMOTE_ADDR']
Than you know exactly what value it has. Compare that to your hardcoded value.
Echo them both so you know exactly what is going on

Reply With Quote
  #8  
Old February 20th, 2013, 06:59 PM
ukndoit ukndoit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 39 ukndoit Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 12 h 16 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by aeternus
as (implicitly) suggested you first echo out $_SERVER['REMOTE_ADDR']
Than you know exactly what value it has. Compare that to your hardcoded value.
Echo them both so you know exactly what is going on


I did that... that is where I got my Ip address to put in the string.

I even echo both in double " so I can copy them exact to see if there is a empty space in the hard coded ip, but there is not.

Ok, I went back and re-copied the value, pasted it in the string and instead of putting:
PHP Code:
 $_compIp '11.12.13.14'

I put:
PHP Code:
 $_compIp "11.12.13.14"


then that worked. I am not sure if it was me re-copying the IP address or putting double quotes around the Stored IP address in the string...

at any rate it is working now.

Thank you very much for your assistance. I appreciate it.

Rich

Reply With Quote
  #9  
Old February 20th, 2013, 07:03 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
good to hear, always just echo out all values you are testing with. saves you a headache

P.s. you might want to read a bit about what the difference is between single and double quotes.

Last edited by aeternus : February 20th, 2013 at 07:05 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Simple IP address check problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap