CodeIgniter Forums
All users with the same ip address, why? - 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: All users with the same ip address, why? (/showthread.php?tid=68855)



All users with the same ip address, why? - Marcolino92 - 09-05-2017

Hi guys, I do not know why, I can not understand it at all since I did not make such strange changes to my script ... but ... I find that every visitor, so every one of my users has the same IP address.

This causes me malfunction to my site, because voting systems and counting visits depend on IP addresses.

(I tried to install a copy of my script into a subfolder, but everything works, but users have different ip addresses.)

I ask you maybe you can understand the cause,
I do not think I have touched anything on config.php or anything else.


RE: All users with the same ip address, why? - JayAdra - 09-05-2017

How are you getting the user's IP address? Is the IP 127.0.0.1 or 192.168.0.1 or similar?


RE: All users with the same ip address, why? - Marcolino92 - 09-05-2017

Yes, 127.0.0.1


RE: All users with the same ip address, why? - JayAdra - 09-05-2017

I'm guessing you're running this app on your local machine then and connecting to it yourself? Because that's your local IP (localhost).

How are you getting the IP? You should use either $_SERVER['REMOTE_ADDR'] or CI's function $this->input->ip_address().

Docs for CI's function:
https://www.codeigniter.com/user_guide/libraries/input.html#CI_Input::ip_address


RE: All users with the same ip address, why? - Marcolino92 - 09-05-2017

I have installed all the base codeignites folders on my web space, later I worked on it to develop my script. I had already tried on other providers and everything was fine.

I take ip addresses with the original function of codeigniter: echo $this->input->ip_address();


RE: All users with the same ip address, why? - InsiteFX - 09-05-2017

See if this works, but do not use this on a real web site for security reasons.

PHP Code:
/**
 * Function to get the client ip address
 *
 * Useage: $ip = getIpAddress();
 *
 * Use for testing only not on a real site!
 */
function getIpAddress()
{
 
   $ipaddress '';

 
   if ($_SERVER['HTTP_CLIENT_IP'])
 
   {
 
       $ipaddress $_SERVER['HTTP_CLIENT_IP'];
 
   }
 
   elseif ($_SERVER['HTTP_X_FORWARDED_FOR'])
 
   {
 
       $ipaddress $_SERVER['HTTP_X_FORWARDED_FOR'];
 
   }
 
   elseif ($_SERVER['HTTP_X_FORWARDED'])
 
   {
 
       $ipaddress $_SERVER['HTTP_X_FORWARDED'];
 
   }
 
   elseif ($_SERVER['HTTP_FORWARDED_FOR'])
 
   {
 
       $ipaddress $_SERVER['HTTP_FORWARDED_FOR'];
 
   }
 
   elseif ($_SERVER['HTTP_FORWARDED'])
 
   {
 
       $ipaddress $_SERVER['HTTP_FORWARDED'];
 
   }
 
   elseif ($_SERVER['REMOTE_ADDR'])
 
   {
 
       $ipaddress $_SERVER['REMOTE_ADDR'];
 
   }
 
   else
    
{
 
       $ipaddress 'UNKNOWN';
 
   }

 
   return $ipaddress;




RE: All users with the same ip address, why? - Marcolino92 - 09-05-2017

Show my correct ip address, yes!

PS: Is the SSL certificate case by chance?


RE: All users with the same ip address, why? - Narf - 09-05-2017

(09-05-2017, 03:21 AM)InsiteFX Wrote: See if this works, but do not use this on a real web site for security reasons.

PHP Code:
/**
 * Function to get the client ip address
 *
 * Useage: $ip = getIpAddress();
 *
 * Use for testing only not on a real site!
 */
function getIpAddress()
{
 
   $ipaddress '';

 
   if ($_SERVER['HTTP_CLIENT_IP'])
 
   {
 
       $ipaddress $_SERVER['HTTP_CLIENT_IP'];
 
   }
 
   elseif ($_SERVER['HTTP_X_FORWARDED_FOR'])
 
   {
 
       $ipaddress $_SERVER['HTTP_X_FORWARDED_FOR'];
 
   }
 
   elseif ($_SERVER['HTTP_X_FORWARDED'])
 
   {
 
       $ipaddress $_SERVER['HTTP_X_FORWARDED'];
 
   }
 
   elseif ($_SERVER['HTTP_FORWARDED_FOR'])
 
   {
 
       $ipaddress $_SERVER['HTTP_FORWARDED_FOR'];
 
   }
 
   elseif ($_SERVER['HTTP_FORWARDED'])
 
   {
 
       $ipaddress $_SERVER['HTTP_FORWARDED'];
 
   }
 
   elseif ($_SERVER['REMOTE_ADDR'])
 
   {
 
       $ipaddress $_SERVER['REMOTE_ADDR'];
 
   }
 
   else
    
{
 
       $ipaddress 'UNKNOWN';
 
   }

 
   return $ipaddress;


Please stop giving this snippet to everybody who has an "IP address problem".

It doesn't matter that you say it is only for test purposes. People will use your "test purposes function" in production, because nobody gave them another solution.


RE: All users with the same ip address, why? - InsiteFX - 09-06-2017

@Narf, Sorry was just trying to see if he had another problem, well noted.