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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler