Welcome Guest, Not a member yet? Register   Sign In
ip adress returns 0.0.0.0
#1

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 !
Reply
#2

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;

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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 ?
Reply
#4

(This post was last modified: 06-29-2017, 09:52 AM by Theo.)

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
Reply
#5

(This post was last modified: 06-29-2017, 10:22 AM by InsiteFX. Edit Reason: Tested on system )

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...
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(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.
Reply
#7

(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
Reply
#8

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB