Advertisement
Virajsinh

OS Information Get Using PhP

Nov 28th, 2022
1,383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | Source Code | 0 0
  1. function getOSInformation()
  2. {
  3.     if (false == function_exists("shell_exec") || false == is_readable("/etc/os-release")) {
  4.         return null;
  5.     }
  6.  
  7.     $os         = shell_exec('cat /etc/os-release');
  8.     $listIds    = preg_match_all('/.*=/', $os, $matchListIds);
  9.     $listIds    = $matchListIds[0];
  10.  
  11.     $listVal    = preg_match_all('/=.*/', $os, $matchListVal);
  12.     $listVal    = $matchListVal[0];
  13.  
  14.     array_walk($listIds, function(&$v, $k){
  15.         $v = strtolower(str_replace('=', '', $v));
  16.     });
  17.  
  18.     array_walk($listVal, function(&$v, $k){
  19.         $v = preg_replace('/=|"/', '', $v);
  20.     });
  21.  
  22.     return array_combine($listIds, $listVal);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement