PHP playground JSON
function getUserIpAddr(){
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
echo 'User Real IP - '.getUserIpAddr();
<?php
// Sample array
$data = array("a" => "Apple", "b" => "Ball", "c" => "Cat");
header("Content-Type: application/json");
echo json_encode($data);
exit();
?>
<?php
header('Content-Type: application/json'); // OR
//header('Content-Type: application/json; charset=utf-8');
$returned_data = array();
// process the request, database access, and add returned data to array:
// for example
$returned_data["name"] = "Luffy";
$returned_data["email"] = "luffy@onepiece.fandom.com";
$returned_data["profile"] = "https://onepiece.fandom.com/wiki/Monkey_D._Luffy";
$json = json_encode($returned_data, true); // convert array to JSON string
echo $json; // return JSON data
?>