|
Posted by Paul Lautman on 09/01/07 11:40
Christian Aastorp wrote:
> I'm a newbie with php, but experienced with other languages. I'm
> maintaining a small site written in php. To ease debugging and updates
> I've used an onscreen reference to indicate identity of included files
> etc.
>
> I don't really want this reference to be visible to anyone but myself.
> So I searched the manual and found some promising predefined variables
> that I used in this code snippet:
>
> <?php
> if ($_SERVER['REMOTE_ADDR'] = "127.0.0.1") {
> echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
> }
>>
>
> This worked spllendidly when I tested running our site locally using
> the XAMPP-bundle. But when I copied the code out to the real server it
> seems that all clients are found at 127.0.0.1!
>
> I'm sure there are lots of better ways both to fix my code, and
> especially totally different ways to do what I'm trying to achive, any
> suggestions very welcome!
As Michael pointed out, what you are actuall y doing here is assiging the
value "127.0.0.1" to the associative array element $_SERVER['REMOTE_ADDR'].
You should write:
<?php
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
echo $level1, '_', $level2, '_', $imageNO, ' ', $display;
}
>
Note the == instead of = and also note the use of single instead of double
quotes around the string, which stops PHP from parsing the string to
discover if any substitution needs to take place.
Navigation:
[Reply to this message]
|