doujian1954 2019-04-13 21:13
浏览 548

如何用混淆的“SERVER_SOFTWARE”确定PHP中的服务器类型

I've secured my server using "mod_security2" and changed the "Server:" header to a different value. It says: "Server: exampleserver". I used the following mod_security options:

ServerTokens Full
SecServerSignature exampleserver

A side effect is that $_SERVER["SERVER_SOFTWARE"] also equals "exampleserver".

Therefore the typical code to determine the server type no longer works:

if( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) 
  echo 'Have Apache';
else
  echo 'Have some other server';

While checking the information available from PHP, I found that this particular PHP7 setup has the "apache2handler" extension loaded in Apache.

So I updated my test to:

$isApache=  extension_loaded('apache2handler')
          ||(strpos(getenv('SERVER_SOFTWARE'),'Apache')!==false);

Is there a better way to determine what the type of server is inside PHP when $_SERVER['SERVER_SOFTWARE'] is not available ?

  • 写回答

1条回答 默认 最新

  • doupuchao4256 2019-04-13 22:15
    关注

    You can use the php_sapi_name() function to determine how PHP is running. On my web server, this returns "apache2handler." On the command line, it returns "cli."

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!