Skip to content
Advertisement

Why is strpos useful/used and what benefits does it have in this example? [closed]

So, I’m debugging a PHP repository and I came across the following lines

if (strpos($_SERVER['HTTP_HOST'],  'selfcaredocument.com') !== false)
{
header("Location: https://iammes.care");
exit;
}

Is this used for security, to not allow access to the page from a URL? I don’t understand what it does. I’d like to know more, if you can give me a little more information. My understanding of strpos is that it is used to find the occurrence of a string. But what is the real purpose of its usage in the example?

Advertisement

Answer

‘HTTP_HOST’

Contents of the Host: header from the current request, if there is one.

See: https://www.php.net/manual/en/reserved.variables.server.php

So if the HTTP_HOST is selfcaredocument.com or contains it, the client will be redirected to a different page.

I would confidently say that this is not a security measure. My guess would be that there is active traffic pointing to the mentioned domain, of which the owner would now like redirected.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement