Example 1 — Check If a Query Variable Was Sent
Ask whether the email field exists in the GET data. When you run this from the command line there is no query string, so the answer is false.
<?php
if (filter_has_var(INPUT_GET, 'email')) {
echo "The email field was sent.", PHP_EOL;
} else {
echo "The email field was not sent.", PHP_EOL;
} How It Works
- INPUT_GET tells PHP to look at the query string of the request (the part after ?).
- filter_has_var() checks whether a variable named email exists there.
- In a browser, visiting page. [email protected] would make the first branch run.
- On the command line there is no query string, so the else branch prints the message.

