PHP $_SERVER ['REMOTE_ADDR'] returns Boru's IP address not Remote IP address

Status
Not open for further replies.

belltown

Member
Messages
97
Reaction score
4
Points
8
Before the migration I was able to log users' IP addresses in my PHP code using $_SERVER ['REMOTE_ADDR']. The same code now logs the IP address of the Boru server.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Use

$_SERVER['X_HTTP_FORWARDED_FOR'];
 

belltown

Member
Messages
97
Reaction score
4
Points
8
I think you mean $_SERVER['HTTP_X_FORWARDED_FOR']

That seems to work on X10hosting. However, to make my code work portably on other hosts that do not supply HTTP_X_FORWARDED_FOR, I wrote the following function which seems to work on all hosts:

Code:
function getClientIP () {
 if (isset ($_SERVER ['HTTP_X_FORWARDED_FOR'])){
  $clientIP = $_SERVER ['HTTP_X_FORWARDED_FOR'];
 }
 elseif (isset ($_SERVER ['HTTP_X_REAL_IP'])){
  $clientIP = $_SERVER ['HTTP_X_REAL_IP'];
 }
 else {
  $clientIP = $_SERVER['REMOTE_ADDR'];
 }
 return $clientIP;
}
 

DeadBattery

Community Support Team
Community Support
Messages
4,018
Reaction score
120
Points
0
I am closing this thread since you seem to have found a fix to your problem. If you have any other problems, feel free to create another support thread.
*****Thread Closed*****
 
Status
Not open for further replies.
Top