简体   繁体   English

PHP $ _SERVER ['HTTP_HOST']转义,这看起来可以接受吗?

[英]PHP $_SERVER['HTTP_HOST'] escaping, does this look acceptable?

I am just learning about escaping things and started reading about how it could be risky to use $_SERVER['HTTP_HOST'] due to XSS attacks. 我正在学习逃避的事情,并开始阅读由于XSS攻击而使用$_SERVER['HTTP_HOST']会有多大风险。

I came up with this and was wondering if I could get some feedback on my attempt. 我想出了这个,并想知道我是否可以得到一些关于我的尝试的反馈。

htmlspecialchars(
    filter_var( $_SERVER[ 'HTTP_HOST' ], FILTER_SANITIZE_URL ),
    ENT_QUOTES, 'UTF-8'
)

Does it look okay? 看起来好吗?

So much depends on this one variable being secure, I just had to ask for input. 这么多取决于这个变量是安全的,我只需要求输入。

EDIT: 编辑:

I will be using this for display throughout the site, including basic anchor-hrefs, form-actions, etc. 我将在整个网站上使用它进行显示,包括基本的锚点hrefs,表单动作等。

It depends on what do you want to use for. 这取决于你想要用什么。 If you want to display it, use htmlspecialchars. 如果要显示它,请使用htmlspecialchars。 If you want to use as a database query, you might use mysql_real_escape_string in case of mysql. 如果要将其用作数据库查询,则可以在mysql的情况下使用mysql_real_escape_string。 (or prepared statements) (或准备好的陈述)

Different escaping functions should be used for different situations, for example: 不同的转义函数应该用于不同的情况,例如:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安全的php主机名信息 - $ _SERVER ['HTTP_HOST']替代方案 - secure php host name information - $_SERVER['HTTP_HOST'] alternative $ _SERVER ['HTTP_HOST']无法识别 - $_SERVER['HTTP_HOST'] not recognized $ _SERVER ['HTTP_HOST']未设置 - $_SERVER['HTTP_HOST'] not set 无法在php mail()中使用变量$ _SERVER ['HTTP_HOST'] - Cannot use variable $_SERVER['HTTP_HOST'] in php mail() 在PHP中,$ _ SERVER ['HTTP_HOST']的Perl等价于什么? - What is the Perl equivalent of $_SERVER['HTTP_HOST'] in PHP? JSP或JavaScript等效于PHP的$ _SERVER [“HTTP_HOST”]? - JSP or JavaScript equivalent to PHP's $_SERVER[“HTTP_HOST”]? Apache代理Lighttpd:在PHP中更改$ _SERVER ['HTTP_HOST'] - Apache proxy to Lighttpd: changing $_SERVER['HTTP_HOST'] in php 在Chrome中,基于$ _SERVER ['HTTP_HOST']的PHP加载CSS失败 - PHP load CSS based on $_SERVER['HTTP_HOST'] fails in Chrome PHP中的HTTP_HOST和SERVER_NAME有什么区别? - What is the difference between HTTP_HOST and SERVER_NAME in PHP? 还有PHP的$ _SERVER ['HTTP_HOST'])的替代方法吗? 适用于不需要完整的编程语言(例如SSI)的Apache - Is there an alternative to PHP's $_SERVER['HTTP_HOST']); for apache that does not require a full blown programming language (e.g. SSI)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM