I'm new to php and right now i'm doing a server management script for server admins. I would like to include some server information in this page and as part of the information I like to include the CPU Name and i did the script.
<?php
$cpuinfo = file("/proc/cpuinfo");
for ($i = 0; $i < count($cpuinfo); $i++)
{
list($item, $data) = split(":", $cpuinfo[$i], 2);
$item = chop($item);
$data = chop($data);
if ($item == "processor") {$total_cpu++; }
if ($item == "vendor_id") { $vendor_id = $data; }
if ($item == "model name") { $cpu_name = $data; }
if ($item == "cpu MHz") {$cpu_speed = " " . floor($data);}
}
$cpu_info = $total_cpu.'x '.$vendor_id.' '.$cpu_name.' '.$cpu_speed." MHz\n";
$cpu = "<p>CPU :".$cpu_info."</p>";
echo $cpu;
?>
when running this script it displays the cpu version but it displays these errors below.
Notice: Undefined variable: total_cpu in /var/www/html/daniel/index.php on line 10 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7
CPU :4x GenuineIntel Intel(R) Xeon(R) CPU X3360 @ 2.83GHz 2825 MHz
Anyone know how to solve the problem?