Using popen() to Read the Output of the Unix who Command
<html>
<head>
<title>Using popen() to Read the Output of the Unix 'who' Command</title>
</head>
<body>
<div>
<h1>Administrators currently logged on to the server</h1>
<?php
$ph = popen( "who", "r" )or die( "Couldn't open connection to 'who' command" );
$host="demo.com";
while ( ! feof( $ph ) ) {
$line = fgets( $ph, 1024 );
if ( strlen( $line ) <= 1 ) {
continue;
}
$line = preg_replace( "/^(\S+).*/",
"<a href=\"mailto:$1@$host\">$1</a><br />\n",
$line );
print "$line";
}
pclose( $ph );
?>
</div>
</body>
</html>
Related examples in the same category