php – 如何检查ini_set是否可以在服务器上工作?

前端之家收集整理的这篇文章主要介绍了php – 如何检查ini_set是否可以在服务器上工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何检查服务器配置是否允许我设置如下选项:
ini_set('upload_max_filesize','8M');

PHP脚本中?这是php.ini directives的列表,但是我无法真正弄清楚如何在进行检查之前更改该值.

检查我是否被允许使用ini_set一些选项,怎么样?

ini_set将成功返回旧值,失败时为false *.有了这个知识,你可以写一个语句来检查你的呼叫是否经过,如下所示.

$result = ini_set ("some_option","some_value");
$failure = (version_compare(PHP_VERSION,'5.3.0') >= 0) ? false : '';
if ($result === $failure)
   echo "Unable to use ini_set to change 'some_option'!";

(*):注意PHP 5.3.0中的返回值从“(空字符串)更改为false.所以你需要检查你当前的PHP版本.

另一种方法是使用ini_get_all,它将为您提供有关每个可用选项的详细信息,它是access level.

$all_option_details = ini_get_all ();

/* see the comments in this post regarding PHP_INI_USER vs INI_USER
 * seems like someone writing the relevant PHP documentation fcuked up
 *
 * props to @soulmerge */

if ($all_option_details['upload_max_filesize']['access'] & INI_USER)
   echo "we are allowed to change upload_max_filesize from with ini_set!";

我想禁用使用ini_set一些选项,怎么样?

有几种使选项不可更改的运行时(以某种方式禁用ini_set)的方法,其中包括以下两种方法,您可以在提供的链接中阅读更多信息.

> PHP: How to change configuration settings

PHP_admin_value name value

Sets the value of the specified directive. This can not be used in .htaccess files. Any directive type set with PHP_admin_value can not be overridden by .htaccess or ini_set(). To clear a prevIoUsly set value use none as the value.

PHP_admin_flag name on|off

Used to set a boolean configuration directive. This can not be used in .htaccess files. Any directive type set with PHP_admin_flag can not be overridden by .htaccess or ini_set().

示例(摘自this文档)

<IfModule mod_PHP5.c>
  PHP_value include_path ".:/usr/local/lib/PHP"
  PHP_admin_flag engine on
</IfModule>

<IfModule mod_PHP4.c>
  PHP_value include_path ".:/usr/local/lib/PHP"
  PHP_admin_flag engine on
</IfModule>
原文链接:https://www.f2er.com/php/130740.html

猜你在找的PHP相关文章