Writing phpinfo() To File

11th July 2008 - 1 minute 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.

  1. ob_start();
  2. phpinfo();
  3. $info = ob_get_contents();
  4. ob_end_clean();
  5.  
  6. $fp = fopen("phpinfo.html", "w+");
  7. fwrite($fp, $info);
  8. fclose($fp);

This is an example of output buffering.

Comments

Permalink
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)

Permalink
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.