PHP Register Globals Off

When PHP 4.2.0 was released, the REGISTER_GLOBALS directive went from ON to OFF. It was a controversial change since it caused older PHP scripts to fail. I had several scripts that were no longer working in the newer PHP default configuration. The good news is, there’s no need to do a massive rewrite of your older scripts. Just reassign your old variables using the new global variables of $_REQUEST, $_POST or $_GET. In the example below, we are reassigning the variables $id, $task and $name to make them accessible.

$id = $_REQUEST['id'];   // When passing variables within a script.
$task = $_POST['task'];  // When using a POST
$name = $_GET['name'];   // When using a GET

One Response to “PHP Register Globals Off”

Leave a Reply