I can get the global ip of a client like below, but is it safety?
<?php
echo $_SERVER[‘REMOTE_ADDR’];
I saw some article that we have to sanitize $_GET, $_POST or $_COOKIE, but how do I treat about $_SERVER?
I can get the global ip of a client like below, but is it safety?
<?php
echo $_SERVER[‘REMOTE_ADDR’];
I saw some article that we have to sanitize $_GET, $_POST or $_COOKIE, but how do I treat about $_SERVER?
$_GET
, $_POST
and $_COOKIE
come from user input, so they should be treated with caution.
While $_SERVER
is generated by PHP interpreter, it also contains lots of user-provided data, such as argv
, QUERY_STRING
, PHP_SELF
, all headers (called HTTP_header_name
) and so on. Treat those as unsafe user input as well.
Never assume that it will only be a browser making a request to your server: attackers can craft special requests very easily.