How can I get the address of IP
of the person who logged into my system?
I searched Google and all I find are queries on third-party sites ( link , #
Does anyone know of any links or scripts (PHP, Python, ...) that do this?
On the link you posted link adding ?format=json
it returns you Ip
in Json
format. The full link you can view here .
You can get Ip
using the getJSON
function of Jquery.
Here's an example.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><scripttype="text/javascript">
$(function () {
$.getJSON("https://api.ipify.org?format=json", function (data) {
alert(data.ip);
});
});
</script>
</body>
</html>
I solved this as follows
function getIP() {
if($_SERVER["HTTP_X_FORWARDED_FOR"]) {
$proxy = '';
if($_SERVER["HTTP_CLIENT_IP"]) {
$proxy = $_SERVER["HTTP_CLIENT_IP"];
} else {
$proxy = $_SERVER["REMOTE_ADDR"];
}
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
if($_SERVER["HTTP_CLIENT_IP"]) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
}
if (empty($proxy)) {
return $ip;
} else {
return $proxy;
}
}
These links are returning the ip that your machine is using (client)
To get the same ip through php you can use this code:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
If you want a function that returns an IP with a higher degree of certainty, it has this function:
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
echo $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
echo $_SERVER['HTTP_X_FORWARDED_FOR']; }
else { echo $_SERVER['REMOTE_ADDR']; }
?>