0

I have a PHP script that shows some server variables, the code is as following :

<?php
$FILTEREDHOST = filter_input(INPUT_SERVER,'HTTP_HOST');
$FILTEREDSELF = filter_input(INPUT_SERVER,'PHP_SELF');

$SERVERHOST = $_SERVER['HTTP_HOST'];
$SERVERSELF = $_SERVER['PHP_SELF'];

var_dump($FILTEREDHOST);
echo "</br>";
var_dump($FILTEREDSELF);
echo "</br>";
var_dump($SERVERHOST);
echo "</br>";
var_dump($SERVERSELF);

The result I get is :

NULL
string(9) "/test.php"
string(17) "www.mysite.com"
string(9) "/test.php" 

Why $FILTEREDHOST is returning NULL ?

My PHP version is 5.5.16

0

1 Answer 1

1

HTTP_HOST is not set if the browser didn't send it.

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

http://php.net/manual/en/reserved.variables.server.php

Sign up to request clarification or add additional context in comments.

3 Comments

why the browser sent it here :$SERVERHOST = $_SERVER['HTTP_HOST']; ??
I think it has to do with the strange side-effects of FastCGI. ch2.php.net/manual/en/function.filter-input.php#77307
Well, you might be right, I used the suggested function in that link and I see the the SERVER variable content and the HTTP_HOST is present.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.