php – 是否有一个很好的替代$_SERVER [‘SERVER_NAME’]?

我在 PHP doc pages上阅读了以下评论

“Be warned that most contents of the Server-Array (even
$_SERVER[‘SERVER_NAME’]) are provided by the client and can be
manipulated. They can also be used for injections and thus MUST be
checked and treated like any other user input.”

那时我在on StackOverflow saying that $_SERVER[‘SERVER_NAME’] is partly server controlled看到了一个话题.

我可以信任这个值来获取我网站的网址吗?如果我不能真正信任$_SERVER [‘SERVER_NAME’],我该如何获得此值?有哪些可能的替代方案及其利弊?

OBS:Apache,Unix上的PHP 5.3.

解决方法

您可以通过在Apache配置中启用UseCanonicalName指令来强制执行此变量的安全性,如 http://www.apacheref.com/ref/http_core/UseCanonicalName.html所述

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...