PHP Valid $_GET Variables

PHP Valid $_GET Variables

A PHP $_GET variable actually exists when it has a distinct value or it is an empty string. For example, let's assume you have the 3 following url strings; example.com?variable, example.com?variable= and example.com?variable=1. Of the three urls, only the third one contains characters for the valid $_GET variable.

The url with ?variable and ?variable= do set the variable; although no characters exist. The code example below would only output a value and the word 'Hello'. Try writing the 3 variations in the url and you will see "Hello" output each time.

$valid = $_GET['variable']; 

if(isset($_GET['variable'])){ 
echo "Hello "; echo $valid; 
}