11th July 2008 - 2 minutes read time
The contents of phpinfo() are quite useful, and it is usually the first thing that many developers perform to make sure that PHP is installed. However, printing out the phpinfo() function can lead to a security risk because it displays a lot of information about the server.
Here is how to write the contents of the phpinfo() function to a file.
ob_start();
phpinfo();
$info = ob_get_contents();
ob_end_clean();
$fp = fopen("phpinfo.html", "w+");
fwrite($fp, $info);
fclose($fp);
This is an example of output buffering.