Why is it not good to access $_SERVER[] directly in PHP?

I have a line like this in my php file:

SERVER_NAME = $_SERVER["SERVER_NAME"];

Open in new window


For some reason, Netbeans flags it with a yellow triangle warning to its left saying:

"Do not access Superglobal $_SERVER Array directly"

Can anyone please give me any explanation why accessing $_SERVER[] could be bad? Or is Netbeans just full of it?
elepilAsked:
Who is Participating?
 
Marco GasiFreelancerCommented:
Because it is reccomended to use the filter_input() function wich allow you to validate and/or sanitize the input before to use it in your script.
0
 
Marco GasiFreelancerCommented:
If you want, you can just remove those warning going to Option->Editor->Hints, and unchecking relative checkboxes under Php language list: I did this because I work with CodeIgniter which has yet it own validating/sanitizing functions (as any other framwork), but if you use just pure php, it's better to use filter_input().
0
 
Dave BaldwinFixer of ProblemsCommented:
SERVER_NAME without a '$' isn't a valid variable anyway.  I use $_SERVER['HTTP_REFERER'] and $_SERVER['REMOTE_ADDR'] fairly often.
0
 
elepilAuthor Commented:
Thanks for input!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.