I have several php scripts that have the following structures:
$count = $_GET['count'];
$sort = $_GET['sort'];
$car = $_GET['car'];
$driver = $_GET['driver'];
...
$SQL = "SELECT car, truck FROM autos WHERE car='$car' AND truck='truck'";
...
Another script will be the identical script except rather than car, truck or the table autos I will be working with another table, different variables and possibly more or less variables. Is there a way or a good design pattern to use such that I only have to write one instance of this script vice the 15 or so I might otherwise have to write.
This has security implications when combined with less than perfect code, but I’ll assume that’s not an issue for you.
A benefit of using extract is you get to specify the behavior when name collisions would occur. You might consider the
EXTR_PREFIX_ALLflag though.Or, just make a white list, which is best imo.