PDA

View Full Version : PHP Help



Trigs
23-01-2009, 10:51 PM
Ay,

I have a login script. Everytime a user logs in, it records their IP. In order to ensure that they aren't using a proxy to hide their IP, I want to be able to record their real IP. Most proxies use the $_SERVER['HTTP_X_FORWARDED_FOR'] header from what I know so I need a PHP script that checks to see if that header (or $_SERVER['VIA'];) exists and if it does, save that IP instead (I can code that last one). Is there a way to check if a SERVER var exists?

Thread moved from Designing & Development by ,Jess, (Forum Super Moderator): Please post in the correct section.

Iszak
23-01-2009, 11:35 PM
Well you can do it two ways, but ones faster than the other.


if (isset($_SERVER['var']))
{

}
or



if (array_key_exists('var', $_SERVER))
{

}
you could also do



if (empty($_SERVER['var']) === false)
{

}
The first one Is faster than the second and I'm not sure about the third.

Trigs
24-01-2009, 01:07 AM
Thanks +rep

DeejayMachoo$
24-01-2009, 04:20 PM
Thanks +rep

Once again iszak got it in a nutshell but you could also do:



if (!$_SERVER['var']!)
{

}

Want to hide these adverts? Register an account for free!