Change background color based on variable with PHP

To change a webpage or html background based on what a PHP variable is, follow this guide:

For practical purposes if a profile is online the PHP variable = 1 making the background green otherwise make it red for 0.


function is_online($id){
    $data = json_decode(file_get_contents("https://someurl/profile?userid=" . $id . ""));
    $status = $data->response->status;
if($status == 1){$color = 'green';}else{$color = 'red';}
return $color;
<body style='background-color : <?php echo is_online(5681);?>'
<h1>More html here</h1>

If profile 5681 is online as per the mock API call in functions.php then the background will be green otherwise the background will be red.