note 33848 added to tutorial.oldcode

From: Date: Wed, 09 Jul 2003 10:51:31 +0000
Subject: note 33848 added to tutorial.oldcode
Groups: php.notes 
Request: Send a blank email to php-notes+get-51766@lists.php.net to get a copy of this message
You can convert 'old php code' that expects register_globals=on to work with register_globals=off by including this script near the top. It improves security by only defining the variables you need. Yet it keeps the simplicity of working with variables with the same name as the form fields. (For those of you who don't know, 'old php code' often uses $formvar instead of $_GET['formvar'] to reference data passed to it from a form.) This script uses Variable Variables. See the section on Variable Variables for more information. Change $_GET to $_POST if your form uses method="post". I looked all over for this info because I like the old way better. Here it is: $expected=array( 'name', // Only accept these variables from a submit! 'email', 'favorite_color' ); for ($i=0;$i < count($expected);$i++) $$expected[$i] = (isset($_GET[$expected[$i]]))?$_GET[$expected[$i]]:NULL; // This is a test. echo "Name: $name<br>"; echo "Email: $email<br>"; echo "Fav. Color: $favorite_color<br>"; ---- Manual Page -- http://www.php.net/manual/en/tutorial.oldcode.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33848 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33848&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33848&report=yes

« previous php.notes (#51766) next »