So I have the following function that's grabbing some data from the query string:
PHP Code:
function getQueryData($dataToGet, $queryIndex=-1)
{
// WARNING: This needs to have inputs sanitized. Do not have this accessible from the internet until this is done! Look at the "filter_input" funtion in PHP's documentation.
if ($queryIndex > -1) {
if (isset($_REQUEST[$dataToGet][$queryIndex])) {
$outputString=$_REQUEST[$dataToGet][$queryIndex];
} else {
if ($_REQUEST[$dataToGet]!="") {
$outputString=$_REQUEST[$dataToGet];
} else {
$outputString="";
}
}
} else {
$outputString=$_REQUEST[$dataToGet];
}
return $outputString;
}
Here's what it should do:
When calling this function I'm using this way for loops (If the query string supplied is in an array):
PHP Code:
$someData=((getQueryData("somedata", $i) >= 1 || getQueryData("somedata", $i) !="") ? getQueryData("somedata", $i) : 123);
And this way for non-arrayed query string parameter (Should also grab the first index in the array when no index is specified and the query string parameter is an array):
PHP Code:
$someData=((getQueryData("somedata") >= 1 || getQueryData("somedata") !="") ? getQueryData("somedata") : 123);
Here's an example way of running this from the query string:
&somedata[]=111&somedata[]=222&somedata[]=333
Which would make somedata[0]=111, somedata[1]=222, somedata[2]=333
or
&somedata=456&somedata[3]=111
Which would make the getQueryData function return 456 in all cases, except when index 3 is called.
Here's my problem:
This line:
PHP Code:
$outputString=$_REQUEST[$dataToGet][$queryIndex];
Doesn't differentiate between proper arrays and splitting up integers/strings. So for example:
somedata[0]=111, somedata[1]=222, somedata[2]=333
getQueryData("somedata", 1); will just return 2, not 222.
I don't want it to split the string/integer up into an array.
Does anyone have a suggestion on how to achieve this?