How can i get ip address location with php? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i get ip address location with php?

I want to write it in php and HTML. HTML for to display the IP address. php to get the IP address. css for fun ...

12th Aug 2018, 8:39 AM
Flip
Flip - avatar
4 Answers
+ 4
<?php $http_client_ip =$_SERVER['HTTP_CLIENT_IP']; $http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR']; $remote_addr= $_SERVER['REMOTE_ADDR']; if(!empty($http_client_ip)){ $ip_address = $http_client_ip; }else if(!empty($http_x_forwarded_for)){ $ip_address = $http_x_forwarded_for; }else { $ip_address = $remote_addr; } echo $ip_address; ?>
12th Aug 2018, 9:24 AM
Amir Ahmad
Amir Ahmad - avatar
+ 3
Flip make one file on your computer save this code in that as php file run there. for that you'll need wamp or xamp server or if you have your own website upload this on server to test it
18th Aug 2018, 6:34 AM
Amir Ahmad
Amir Ahmad - avatar
+ 1
People can mask their IP address(es) so, for what it's worth: https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
12th Aug 2018, 9:21 AM
Janningā­
Janningā­ - avatar
+ 1
I want the IP address to display in the html document... https://code.sololearn.com/W60imzSqyAKI/?ref=app
18th Aug 2018, 5:24 AM
Flip
Flip - avatar