views:

317

answers:

2

Hello, I am attempting to get a list of dependable(consistent across requests) list of "hidden" constants in PHP(as in, the client-side won't know about it in most cases without hacking).

Some of the things I am interested in is the following:

  1. ./configure options.
  2. I would also like the very first System value in phpinfo.
  3. The loaded PHP modules(as shown in the Apache section)
  4. The build date of PHP.
  5. Registered PHP streams
  6. Registered stream socket transports
  7. Registered stream filters

How can I get either just a portion of the phpinfo or get these values as a regular string? Note that it doesn't matter if there if markup included, but I don't want to parse the phpinfo as that just seems really slow and surely there is a better way..

+4  A: 

Most of the stuff available from phpinfo() can be found in constants. Try looking through:

print_r(get_defined_constants());

Or the functions on this page: http://us.php.net/manual/en/ref.info.php. There are tons of functions to get information about specific extensions.

The following functions might be worth looking at:

ini_get() http://us.php.net/manual/en/function.ini-get.php
getenv() http://us.php.net/manual/en/function.getenv.php
get_cfg_var() http://us.php.net/manual/en/function.get-cfg-var.php

Chacha102
Well, I do not want to screw up the output buffering though because I may use it in the future for the actual pages
Earlz
Output Buffering can be nested. That line of code won't screw anything up if you implement something in the future.
Chacha102
@Chacha102: `ob_end_clean()` will turn off output buffering (another call to `ob_start()` is needed).
Alix Axel
Hmmmm .... Then how are you suppose to nest OB's if you can't break out of them...
Chacha102
http://us.php.net/manual/en/function.ob-end-flush.php says that you have to call it multiple times for each `ob_start`, and it says that it stopps the topmost output buffer, meaning the documentation contradicts itself.
Chacha102
The documentation is fine. You are reading `ob_end_flush()` page not the `ob_end_clean()` page. Anyway you should be using `ob_get_clean()` instead of `ob_end_clean()`.
Alix Axel
Ah .... that makes sense. Took out the output buffering part.
Chacha102
+5  A: 

Here you go:

  1. ini_get_all() or get_loaded_extensions() were the closest I could find
  2. php_uname()
  3. apache_get_modules()
  4. phpversion() was the closest I could find
  5. stream_get_wrappers()
  6. stream_get_transports()
  7. stream_get_filters()

See also get_defined_constants() and some more.


As Chacha102 mentioned you can also use output control functions and parse the phpinfo():

ob_start();
phpinfo();
$variable = ob_get_contents();
ob_get_clean();

Due to the use of ob_get_clean() it won't mess up other output buffering levels you may be using.

Alix Axel
I believe `PHP_VERSION` is a constant that would work aswell.
Chacha102
Yes, but I prefer to use the function. =)
Alix Axel
I'll bet you in microptmizations that the constant is faster than the function. Then again, microptimizations are stupid anyway.
Chacha102
@Chacha102: My answer is function only, no constants allowed! :P
Alix Axel
Constants are annoying because something they aren't defined, or PHP tries to use them as a string instead of a constant.
Chacha102