Writing phpinfo() To File

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.

$info = ob_get_contents();
$fp = fopen("phpinfo.html", "w+");
fwrite($fp, $info);

This is an example of output buffering.


Thanks for the tip. It would be good to just have it save as Plain Text format rather than html as this would make diff/merge of different server settings much easier. Is there a way to strip the html ?

Lem (Thu, 08/27/2015 - 02:25)

Well, you can generate it from the command line with php --infoThat doesn't have any HTML in it :)

Add new comment

The content of this field is kept private and will not be shown publicly.