Ensure that url was called with specific parameter

I have a script.php that can be accessed by browser. To be able to do anything it has to be called by using script.php?abc=1
What is the best way to check if parameter was called and if not, stop the script? Would checking for $_SERVER['REQUEST_URI'] be enough? Do all browsers use it?

Thank you


You can use the isset() function – this is a very common thing to use if you need to check whether input values have been provided or not.

In the simplest case, just exit the script if the value isn’t set:

if (!isset($_GET["abc"])) exit();

Documentation: https://www.php.net/manual/en/function.isset.php

P.S. $_SERVER['REQUEST_URI'] provides the whole URI following the domain, including the path and the whole querystring. So you could pick that apart to get the value you want, but it’s pointless because $_GET["abc"] will take you straight to it. See this answer for an example of the difference.