Skip to content

Instantly share code, notes, and snippets.

@AntoineTurmel
Created May 15, 2020 10:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntoineTurmel/7650c7dde940c50423d3b8ef18e6a85e to your computer and use it in GitHub Desktop.
Save AntoineTurmel/7650c7dde940c50423d3b8ef18e6a85e to your computer and use it in GitHub Desktop.
Display PHP version with ?info=phpVersion or Raspberry Pi Revision Model with ?info=device (it needs pi-model.json from https://github.com/gablau/rpi-revision-codes-utility/blob/master/pi-model.json )
<?php
function getRaspberryPiVersion($revision) {
$fp = fopen('pi-model.json', 'r');
$filename = "pi-model.json";
$contents = fread($fp, filesize($filename));
fclose($fp);
$json = json_decode($contents);
foreach ($json as $item) {
if ($item->Code == $revision) {
return $item->Model;
}
}
}
$myObj = new \stdClass();
foreach ($_GET as $key => $value) {
$myObj->$key = $value;
}
$myJSON = json_encode($myObj);
if ($myObj->info == "phpVersion") {
echo phpversion();
}
if ($myObj->info == "device") {
$distro = exec('cat /etc/os-release | grep ^ID=');
if (strpos($distro, 'raspbian') !== FALSE) {
$revision = exec("cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//'");
echo 'Raspberry Pi ' . getRaspberryPiVersion($revision);
}
else {
echo '';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment