How to get PHP information when phpinfo() function is disabled

Many web hosting companies choose to block the phpinfo function. When you try to run the function, you will get a PHP warning in the error_log file:

[04-Apr-2018 17:23:48 UTC] PHP Warning: phpinfo() has been disabled for security reasons in /home/test/public_html/test2.php on line 2

The content of the test2.php file being:

<?php
echo phpinfo();
?>

So what you can do to get some PHP values for options like post_max_size, max_execution_time, memory_limit, post_max_size, upload_max_filesize etc? 

You can use two other PHP functions – ini_get_all and ini_get. The first one will list all the PHP registered configuration options. Use like:

<?php
foreach (ini_get_all(null, false) as $option => $value) echo "$option=$value"."<br/>";
?>

The result will be:

allow_url_fopen=1
allow_url_include=
arg_separator.input=&
arg_separator.output=&
assert.active=1
assert.bail=0
assert.callback=
assert.exception=0
assert.quiet_eval=0
assert.warning=1
auto_append_file=
auto_detect_line_endings=0
auto_globals_jit=1
auto_prepend_file=
bcmath.scale=0
browscap=
cgi.check_shebang_line=1
cgi.discard_path=0
cgi.fix_pathinfo=1
cgi.force_redirect=1
cgi.nph=0
cgi.redirect_status_env=
cgi.rfc2616_headers=0
cli.pager=
cli.prompt=\b \> 
curl.cainfo=
date.default_latitude=31.7667
date.default_longitude=35.2333
date.sunrise_zenith=90.583333
date.sunset_zenith=90.583333
date.timezone=UTC
default_charset=UTF-8
default_mimetype=text/html
default_socket_timeout=60
disable_classes=
disable_functions=system,phpinfo,shell_exec
display_errors=
display_startup_errors=
doc_root=
docref_ext=
docref_root=
enable_dl=
enable_post_data_reading=1
error_append_string=
error_log=error_log
error_prepend_string=
error_reporting=32759
exit_on_timeout=0
expose_php=
extension_dir=/opt/cpanel/ea-php70/root/usr/lib64/php/modules
fastcgi.logging=1
file_uploads=1
filter.default=unsafe_raw
filter.default_flags=
from=
gd.jpeg_ignore_warning=0
highlight.comment=#FF8000
highlight.default=#0000BB
highlight.html=#000000
highlight.keyword=#007700
highlight.string=#DD0000
html_errors=1
ic24.api.log_msg_errors=0
ic24.api.max_timeout=7
ic24.api_access_key=
ic24.api_check_ip=1
ic24.cache_path=
ic24.dump_cache=0
ic24.enable=0
ic24.home_dir=
ic24.phperr.enable=auto
ic24.phperr.ignore=0
ic24.sec.approve_included_files=
ic24.sec.block_stdin=1
ic24.sec.block_uploaded_files=1
ic24.sec.enable=auto
ic24.sec.exclusion_key=
ic24.sec.stop_on_error=1
ic24.sec.trusted_include_paths=
ic24.slt=7
ic24.update_domains_retry_interval=30
iconv.input_encoding=
iconv.internal_encoding=
iconv.output_encoding=
ignore_repeated_errors=
ignore_repeated_source=
ignore_user_abort=0
implicit_flush=
include_path=.:/opt/cpanel/ea-php70/root/usr/share/pear
input_encoding=
internal_encoding=
ioncube.loader.encoded_paths=
log_errors=1
log_errors_max_len=1024
mail.add_x_header=1
mail.force_extra_parameters=
mail.log=
max_execution_time=600
max_file_uploads=20
max_input_nesting_level=64
max_input_time=60
max_input_vars=1000
mbstring.detect_order=
mbstring.encoding_translation=0
mbstring.func_overload=0
mbstring.http_input=
mbstring.http_output=
mbstring.http_output_conv_mimetypes=^(text/|application/xhtml\+xml)
mbstring.internal_encoding=
mbstring.language=neutral
mbstring.strict_detection=0
mbstring.substitute_character=
mcrypt.algorithms_dir=
mcrypt.modes_dir=
memory_limit=512M
mysqli.allow_local_infile=1
mysqli.allow_persistent=1
mysqli.default_host=
mysqli.default_port=3306
mysqli.default_pw=
mysqli.default_socket=/var/lib/mysql/mysql.sock
mysqli.default_user=
mysqli.max_links=-1
mysqli.max_persistent=-1
mysqli.reconnect=0
mysqli.rollback_on_cached_plink=0
mysqlnd.collect_memory_statistics=
mysqlnd.collect_statistics=1
mysqlnd.debug=
mysqlnd.fetch_data_copy=0
mysqlnd.log_mask=0
mysqlnd.mempool_default_size=16000
mysqlnd.net_cmd_buffer_size=4096
mysqlnd.net_read_buffer_size=32768
mysqlnd.net_read_timeout=31536000
mysqlnd.sha256_server_public_key=
mysqlnd.trace_alloc=
open_basedir=
openssl.cafile=
openssl.capath=
output_buffering=0
output_encoding=
output_handler=
pcre.backtrack_limit=1000000
pcre.jit=1
pcre.recursion_limit=100000
pdo_mysql.default_socket=/var/lib/mysql/mysql.sock
phar.cache_list=
phar.readonly=1
phar.require_hash=1
phpd=1
phpd.t=1
post_max_size=32M
precision=14
realpath_cache_size=4096K
realpath_cache_ttl=120
register_argc_argv=1
report_memleaks=1
report_zend_debug=1
request_order=GP
sendmail_from=
sendmail_path=/usr/sbin/sendmail -t -i
serialize_precision=100
session.auto_start=
session.cache_expire=180
session.cache_limiter=nocache
session.cookie_domain=
session.cookie_httponly=
session.cookie_lifetime=0
session.cookie_path=/
session.cookie_secure=
session.entropy_file=/dev/urandom
session.entropy_length=32
session.gc_divisor=0
session.gc_maxlifetime=1440
session.gc_probability=0
session.hash_bits_per_character=5
session.hash_function=0
session.lazy_write=1
session.name=PHPSESSID
session.referer_check=
session.save_handler=files
session.save_path=/var/cpanel/php/sessions/ea-php70
session.serialize_handler=php
session.upload_progress.cleanup=1
session.upload_progress.enabled=1
session.upload_progress.freq=1%
session.upload_progress.min_freq=1
session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix=upload_progress_
session.use_cookies=1
session.use_only_cookies=1
session.use_strict_mode=
session.use_trans_sid=
short_open_tag=1
SMTP=localhost
smtp_port=25
soap.wsdl_cache=1
soap.wsdl_cache_dir=/tmp
soap.wsdl_cache_enabled=1
soap.wsdl_cache_limit=5
soap.wsdl_cache_ttl=86400
sql.safe_mode=
sqlite3.extension_dir=
sys_temp_dir=
track_errors=
unserialize_callback_func=
upload_max_filesize=32M
upload_tmp_dir=
url_rewriter.tags=a=href,area=href,frame=src,input=src,form=fakeentry
user_agent=
user_dir=
user_ini.cache_ttl=300
user_ini.filename=.user.ini
variables_order=GPCS
xmlrpc_error_number=0
xmlrpc_errors=0
zend.assertions=-1
zend.detect_unicode=1
zend.enable_gc=1
zend.multibyte=0
zend.script_encoding=
zlib.output_compression=0
zlib.output_compression_level=-1
zlib.output_handler=

With ini_get you will only get values for specific PHP options. For example:

<?php

echo ini_get('max_execution_time')."<br/>";
echo ini_get('memory_limit')."<br/>";
echo ini_get('upload_max_filesize')."<br/>";
//etc
?> 
Web links to PHP functions discussed in this article: phpinfo ; ini_get_all ; ini_get

Related KB article: Disable dangerous PHP functions on your web hosting server

Share this post: