[FX.php List] [OFF] Getting visitor's IP

Leo R. Lundgren leo at finalresort.org
Fri Aug 22 16:56:37 MDT 2008


Actually, it's nicer to use isset() and assume that if that key is  
set, the server did put something into it.

$remoteHost = (isset($_SERVER['HTTP_PC_REMOTE_ADDR']) ? $_SERVER 
['HTTP_PC_REMOTE_ADDR'] : $_SERVER['REMOTE_ADDR']);


22 aug 2008 kl. 23.41 skrev Leo R. Lundgren:

> The ?: is more of an operator. See the manual :)
>
> I use strlen() to check if there's any data in the first key. If  
> there is, use it, otherwise use the other key. As I've mentioned  
> before I've come to the conclusion that it's not notably slower  
> than using isset() (which would return TRUE for a var that is set,  
> even if it doesn't contain any data).
>
> For the perfectionist, note that there is no need to have the  
> surrounding () in the expression. I just use it for readability. In  
> actuality, I think it's technically faster to leave them out. But  
> unless you know that you need to remove them, it's not an issue.  
> Just mentioning it to lay off the one whould point it out otherwise :P
>
> 22 aug 2008 kl. 23.32 skrev Jonathan Schwartz:
>
>> Interesting.  What function is that?  Also, what purpose does  
>> strlen provide to the function?
>>
>> Thx
>>
>>> I'm sorry, I haven't followed this thread almost at all,  
>>> honestly. But reading the below quote makes me think that someone  
>>> is wondering whether to use REMOTE_ADDR or HTTP_PC_REMOTE_ADDR.
>>>
>>> If so, here's my suggestion:  $remoteHost = (strlen($_SERVER 
>>> ['HTTP_PC_REMOTE_ADDR']) ? $_SERVER['HTTP_PC_REMOTE_ADDR'] :  
>>> $_SERVER['REMOTE_ADDR']);
>>>
>>> I'm probably so off track here :-)
>>>
>>>
>>> 22 aug 2008 kl. 18.01 skrev Jonathan Schwartz:
>>>
>>>> Kevin,
>>>>
>>>> Are you sure that it is OS X Server making the change?  I admit  
>>>> that I never spent the time trying to nail down the source, but  
>>>> I assumed that it was the PHP version or web server.  I have  
>>>> always used OS X Server 10.4, yet have had to fiddle with the  
>>>> setting just the same.
>>>>
>>>> Jonathan
>>>>
>>>>
>>>>>
>>>>> You *can*, but normalising them makes your code portable to  
>>>>> other systems,
>>>>> and future-proofs it against changes in OS X Server (what if  
>>>>> suddenly they
>>>>> revert to using REMOTE_ADDR?).
>>>>
>>>> --
>>>> Jonathan Schwartz
>>>> Exit 445 Group
>>>> jonathan at exit445.com
>>>> http://www.exit445.com
>>>> 415-370-5011
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>>
>>> -|
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>>
>> -- 
>> Jonathan Schwartz
>> Exit 445 Group
>> jonathan at exit445.com
>> http://www.exit445.com
>> 415-370-5011
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>
> -|
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list


-|



More information about the FX.php_List mailing list