PHP help - user defined variables
Discussion
I need to create a form to post to another page containing all the user defined variables. Best I can come up with at the moment is this:
cheers
php said:Trouble is this includes EVERY variable including server and environment ones. Anyone know how to just get the user defined ones?
$array=$GLOBALS[GLOBALS];
foreach ($array as $i => $value) {
echo "< input type=hidden name=$i value=$array[$i] >\n";
}
cheers
I'd probably write them to a database and then use a session id to track and re-load them.
Alternatively you could use a cookie.
Or, you could filter out unwanted elements:
..if you follow me.
>> Edited by page3 on Tuesday 20th December 10:07
Alternatively you could use a cookie.
Or, you could filter out unwanted elements:
php said:
//get variables
$passedVariableNames = array_keys( $_REQUEST);
//reduce them to only those we want
$passedAttributeNames = array_filter( $passedVariableNames, "ItemMatchesAttribute" ) ;
//now walk through the array
foreach( $passedAttributeNames as $attributeKey=>$attributeName) {
// get the attribute id from the name
$attributeNameItems = explode( $servSeparator, $attributeName);
// the id will be the second item in the array
$id = $attributeNameItems[ 1];
etc...
Defined ItemMatchesAttributes thus:
function ItemMatchesAttribute( $item)
{
global $attributePrefix;
// check if the item starts with the attributeprefix
return ( substr( $item, 0, strlen( $attributePrefix)) ==$attributePrefix);
}
Where you have defined attributeprefix something like:
$attributePrefix = "ServAttr";
..if you follow me.
>> Edited by page3 on Tuesday 20th December 10:07
Trouble is $_REQUEST only gives the passed variables (form the previous pages POST request) and the function ItemMatchesAttribute looks to be comparing the variable name with whatever $attributePrefix is defined as. I don't know what the names are of the defined variables and hence can't do a comparison.
Closest I can get it to use $GLOBAL and create a list of ignorable names like GATEWAY_INTERFACE, SERVER_SOFTWARE etc.
Any more suggestions welcome
Closest I can get it to use $GLOBAL and create a list of ignorable names like GATEWAY_INTERFACE, SERVER_SOFTWARE etc.
Any more suggestions welcome
KITT said:What I do is name all my form variables ServAttr_XXX where XXX changes. My filter function therefore removes all variables that don't start with this and then I explode it (on the '_') to get my proper variable name/value pair. Works for me
Trouble is $_REQUEST only gives the passed variables (form the previous pages POST request) and the function ItemMatchesAttribute looks to be comparing the variable name with whatever $attributePrefix is defined as. I don't know what the names are of the defined variables and hence can't do a comparison.
Closest I can get it to use $GLOBAL and create a list of ignorable names like GATEWAY_INTERFACE, SERVER_SOFTWARE etc.
Any more suggestions welcome![]()
I might be misunderstanding you though or this might not work for you.Ah I see.
I'm actually writing some code that other web programmers will include in their own code and it needs to be able to pass on any defined variables to another page. Hence I won't know what variables have been defined by the other developer(s). I've created a solution where they use fill an array with the names of their defined variables so I can ensure they get passed on. It works for now anyway!
cheers
I'm actually writing some code that other web programmers will include in their own code and it needs to be able to pass on any defined variables to another page. Hence I won't know what variables have been defined by the other developer(s). I've created a solution where they use fill an array with the names of their defined variables so I can ensure they get passed on. It works for now anyway!
cheers

Can you just forward the $_POST vars? That way you only send what ever came through from the original form?
www.w3schools.com/php/php_forms.asp
If not, how are these User Vars created?
best
Ex
www.w3schools.com/php/php_forms.asp
If not, how are these User Vars created?
best
Ex
php said:Now, kittscode.inc needs a way of knowing about $RandomVar so that when the page is reloaded with a POST form, $RandomVar has the original value.
if ($RandomVar=="" )
$RandomVar=GetValueForRadomVar();
//KITT's code here:
include('kittscode.inc');
>> Edited by KITT on Tuesday 20th December 16:17
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


