note 87582 added to language.variables.scope

From: Date: Thu, 11 Dec 2008 15:24:42 +0000
Subject: note 87582 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-148030@lists.php.net to get a copy of this message
A great way to get all the post/get variables. Beware: may have security issues: <?php //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //the following function will accept the get or post //collection and create variables out of the submitted data function createVars(&$arr_post_var) { if ( $arr_post_var ) { foreach ( $arr_post_var as $strKey=>$strItem ) { $strItem = cleanItem($strItem); eval("global \$$strKey;\$$strKey=\"$strItem\";"); } } } //ENd function createVars(&$arr_post_var) //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ?> so now all you do <?php if ( $_GET ) { createVars($_GET); } if ( $_POST ) { createVars($_POST); } ?> The idea behind this approach is this: if you are passing a querystring from ajax then whatever variables you have in your querystring, the function above will create equivalent php variables and assign the proper value. So essentially if your querystring has something like the following: "firstname=shah&phone=555555" then in your php you will have $firstname="shah"; $phone="555555"; But please note this might pose a security threat. ---- Server IP: 208.69.120.35 Probable Submitter: 209.125.98.221 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/87582 Del: integrated -- https://master.php.net/note/delete/87582/integrated Del: useless -- https://master.php.net/note/delete/87582/useless Del: bad code -- https://master.php.net/note/delete/87582/bad+code Del: spam -- https://master.php.net/note/delete/87582/spam Del: non-english -- https://master.php.net/note/delete/87582/non-english Del: in docs -- https://master.php.net/note/delete/87582/in+docs Del: other reasons-- https://master.php.net/note/delete/87582 Reject -- https://master.php.net/note/reject/87582 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148030) next »