Created
May 15, 2020 10:09
-
-
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 )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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