# How can I grab the user's IP address?

I want to store the user's IP address in a Joomla 3.5 component; with 2.5, I did a

$ip = JRequest::getVar('REMOTE_ADDR', '', 'SERVER');  Which is the most efficient way to get the IP address from a client using the JInput class, since JRequest is deprecated? ## 2 Answers Please check this code - $jinput = JFactory::getApplication()->input;

$ip =$jinput->server->get('REMOTE_ADDR', '', '');

//Here default value and filter are null, so you can write

$ip =$jinput->server->get('REMOTE_ADDR');


By this you can get the ip address.

• I don't know, what the 3rd parameter 'SERVER' should do. It's a filter, but not a standard one; should we change this to 'CMD' or remove the 3rd parameter, because CMD is the default one? Or can I define a filter by myself in Joomla 3.x? – Tom Kuschel Apr 4 '16 at 14:39
• Yes SERVER wasnt required and you can leave the last parameter as Blank. – Joomler Apr 5 '16 at 7:07
• I believe the default value and filter are automatically null, so if they're not going be defined by you, then you can replace ->get('REMOTE_ADDR', '', '') with ->get('REMOTE_ADDR') – Lodder Apr 5 '16 at 22:37

I put a one-liner - and it works similar to your answer, because I do not use the object $jinput more than once; again thank you Joomler +1: $ip = JFactory::getApplication()->input->server->get('REMOTE_ADDR','');


You could remove the second parameter too. If so, the \$ip will be set to null if REMOTE_ADDR is not available.