Getting ip address with PHP

Joined
Sep 30, 2017
Messages
38
Best answers
0
Ratings
1
Points
0
#1
Hello,

I'm trying to get my ip with:
PHP:
$_SERVER['REMOTE_ADDR'];
The thing is that i'm getting a different address with php than from websites like myip.com
I've read that there is no 100% reliable way to get an ip address, but what would be my best option using only php?
Thanks. :)
 
Joined
Dec 27, 2017
Messages
1
Best answers
0
Ratings
1
Points
0
#2
Hello,
You can try this:

PHP:
	if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	} 
	elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	} 
	else {
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	echo 'ip is: '.$ip;
 
Latest Threads
  • Deleted
  • Deleted by Localnode
  • Reason: Wrong section
Replies
0
Views
4
  • Deleted
  • Deleted by fwh
Replies
0
Views
1
Replies
13
Views
95
Recommended Threads
Replies
5
Views
1,145
Replies
10
Views
2,125
Replies
2
Views
676
Replies
13
Views
2,884

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top