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

I just found out about escaping things and started reading about how risky it would be to use $_SERVER['HTTP_HOST']because of XSS attacks.

I came up with this and wondered 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 good?

So much depends on how secure this single variable is, I just needed to request input.

EDIT:

I will use this to display on the entire site, including the basic hrefs bindings, action forms, etc.

+3
source share
2 answers

Different screening functions should be used for different situations, for example:

+3

, . , htmlspecialchars. , mysql_real_escape_string mysql. ( )

+3

Source: https://habr.com/ru/post/1718314/


All Articles