This is in my php page
// Change the line below to your timezone!
date_default_timezone_set('Asia/Manila');
$date = date('m/d/Y h:i:s a', time());
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'];}
//print json_encode(array('ip' => $ip));
//echo $date;
echo json_encode(array(
'date' => $date,
'ip' => $ip
));
This is in my ajax
var currentservertime = "";
var clientip = "";
$.ajax({
url: '../currenttime.php',
type: 'POST',
dataType: "json",
success: function(data) {
currentservertime = data.date;
clientip = data.ip;
},
error: function(data) {
var message = "Error Occured!";
$("#dialog").html(message);
$("#dialog").dialog({
title: dialogtitle
});
$("#dialog").dialog("open");
}
});
Then I have console.log(clientip)
in a button click it out puts
::1
In console. Why is this the IP that I am getting in PHP page.
The sample I followed is found here