View Full Version : php code does work
calvynlee
11-20-2007, 02:06 PM
Dear mate...
I have add this code to my website
<h4>Your IP Is </h4>
<?php $ip=@$REMOTE_ADDR;
echo "<b>IP Address= $ip</b>"; ?>
i copy this part from Whatismyip clone which located at http://www.icalvyn.com/ip
the code i paste at LittlePenang (http://www.littlepenang.com/blog) the "about me" box, but the IP address does appear
need your valuable opinion
ses5909
11-20-2007, 02:31 PM
You need to replace the $REMOTE_ADDR with
$_SERVER['REMOTE_ADDR']
The way you are doing it now, $REMOTE_ADDR probably hasn't been set anywhere which is why it is null.
calvynlee
11-23-2007, 04:44 PM
hey, thank, it works,
but i don understand why after add in some additional code, then it will works..
"$REMOTE_ADDR" should be the coding right?
ses5909
11-24-2007, 07:00 AM
No Calvyn, the only was that would work is if somewhere above the code you would have seen:
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
SarahG
11-25-2007, 10:20 PM
It could also be that these two sites appear to be on different servers (well one loads and one doesn't at present so I can only assume they are). If the PHP settings on the icalvyn one has global variables set to on then $REMOTE_ADDR would work, however if the latter has them off (which it clearly seems to be the case) then it wouldn't.
However the best way to ensure portable code is to use Sara's suggested method of $_SERVER['REMOTE_ADDR'] anyway. Same for all global variables.
ses5909
11-26-2007, 05:20 AM
Good point Sarah!
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.