Welcome aboard! We are happy you are here and wish you good net-raft!
<!doctype html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="/scripts/file.js"></script>
</head>
<body>
<div class="myip"></div>
<script type="text/javascript">
$(document).ready(function () {
console.log($(this).userip());
});
</script>
</body>
</html>
// this placed into /scripts/file.js
$(document).ready(function(){
$.fn.extend({
userip: function () {
$.ajax({ url: '/functions_php/file.php',
data: 'functionName=getmyip',
type: 'get',
success: function (data) {
$(".myip").text(data);
}
});
}
});
});
// this placed into /functions_php/file.php
continuing :)
// this placed into /functions_php/file.php
<?php
$functionName = filter_input(INPUT_GET, 'functionName');
if ($functionName == "getmyip") {
getmyip();
}
function getmyip() {
$ipv = $_SERVER['REMOTE_ADDR'];
echo $ipv;
}
?>
// you get real client ip address (not server address) only this way
<!DOCTYPE html>
<html>
<body>
<?php
$query = @unserialize(file_get_contents('http://ip-api.com/php/'));
if($query && $query['status'] == 'success') {
echo $query['query'];
}
?>
</body>
</html>
The most helpful PHP solutions
detect browser phpPHP Click to see more ... 4.6K 408