简体   繁体   中英

PHP filter_input not working

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM