CodeIgniter Forums
ip adress returns 0.0.0.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: ip adress returns 0.0.0.0 (/showthread.php?tid=68361)



ip adress returns 0.0.0.0 - Theo - 06-29-2017

Hello guys,

I've a problem ! I want to get remote ip adress and when i use : <?php echo $this->input->ip_address();?> it returns me : 0.0.0.0
And when i try <?php echo $_SERVER['REMOTE_ADDR']; ;?> it returns nothing ...
I'm using a dedicated server runing on plesk , on cent os !!!

Do you have an idea about this thing ?

Thanks !


RE: ip adress returns 0.0.0.0 - InsiteFX - 06-29-2017

It could be because your behind a proxy server or something else.

Try this and see what you get, if still 0 then look at your log files.

PHP Code:
function getRealIpAddr()
{
 
   if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
 
   {
 
     $ip=$_SERVER['HTTP_CLIENT_IP'];
 
   }
 
   elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
 
   {
 
     $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
 
   }
 
   else
    
{
 
     $ip=$_SERVER['REMOTE_ADDR'];
 
   }
 
   return $ip;




RE: ip adress returns 0.0.0.0 - Theo - 06-29-2017

Hello, and thank you for your help !

When i use your script outside of CI the $ip = $_SERVER['REMOTE_ADDR']; works !
When inside, it's not working ... Is it a CI configuration problem ?


RE: ip adress returns 0.0.0.0 - Theo - 06-29-2017

You can have a look at my code : https://pastebin.com/xwPRhsJv (available for 1day)

This script should return false on ip check, but it still goes on Sad


RE: ip adress returns 0.0.0.0 - InsiteFX - 06-29-2017

Add the method I gave you to a CI helper and then call it were your calling it in your controller and see if that works.

I just tried it on my system here and it works fine...


RE: ip adress returns 0.0.0.0 - Narf - 06-30-2017

(06-29-2017, 10:12 AM)InsiteFX Wrote: Add the method I gave you to a CI helper and then call it were your calling it in your controller and see if that works.

I just tried it on my system here and it works fine...

Don't.

It won't solve anything, and it makes you vulnerable to IP address spoofing.


RE: ip adress returns 0.0.0.0 - Theo - 06-30-2017

(06-30-2017, 01:17 AM)Narf Wrote:
(06-29-2017, 10:12 AM)InsiteFX Wrote: Add the method I gave you to a CI helper and then call it were your calling it in your controller and see if that works.

I just tried it on my system here and it works fine...

Don't.

It won't solve anything, and it makes you vulnerable to IP address spoofing.

Ok ok Wink


RE: ip adress returns 0.0.0.0 - InsiteFX - 06-30-2017

Narf is correct on that one, I should have mentioned that!

I was stating to do that for testing your problem with the
IP Address not for production Code.

Thanks @Narf for clarifying that.