CodeIgniter Forums

Full Version: All users with the same ip address, why?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
How are you getting the user's IP address? Is the IP 127.0.0.1 or 192.168.0.1 or similar?
Yes, 127.0.0.1
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/l...ip_address
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();
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;

Show my correct ip address, yes!

PS: Is the SSL certificate case by chance?
(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.
@Narf, Sorry was just trying to see if he had another problem, well noted.