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

    评论

报告相同问题?

悬赏问题

  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现