Folks,
My original url is this:
You make a METHOD=GET form submission to do a keyword search on my database and you get forwarded to:
Now, I have code to check if the url contains the “table” and “column” params or not.
I am checking like this the lengthy way ….,
[code]
//SECTION: WHITE-LISTS.
//Valid list of Mysql Tables.
$tables_white_list = array(‘sale’,’sold’,’links’);
//Valid list of Mysql Table Columns.
$columns_white_list = array(’email’,’domain’,’url’,’anchor’,’description’,’keyword’);
//SECTION: VALIDATE SERP URL.
//Check if “table” exists or not in Url’s Query String.
if(!empty(trim($_REQUEST[‘table’])) && is_string(trim($_REQUEST[‘table’])))
{
if(in_array(trim($_REQUEST[‘table’]),$tables_white_list)) //MySql Tbl to Search.
{
$table = trim($_REQUEST[‘table’]);
}
else
{
die(‘Invalid Table!’);
}
}
else
{
die(‘Select Table!’);
}
//Check if “column” exists or not in Url’s Query String.
if(!empty(trim($_REQUEST[‘column’])) && is_string(trim($_REQUEST[‘column’])))
{
if(in_array(trim($_REQUEST[‘column’]),$columns_white_list)) //MySql Tbl Col to search.
{
$column = trim($_REQUEST[‘column’]);
}
else
{
die(‘Invalid Column!’);
}
}
else
{
die(‘Select Column!’);
}
Can you see the two sets of IFs doing the checking here ? This is too much code. Let’s try cutting down on it by adding the “table” and “column” onto an array and then looping through the array to check if the array values (eg. “table”, “column”) exists in the url or not. How to do this your shortened way ?
I am trying to shorten it and if I manage it then I will mention here but you are a pro and can shorten it to the min and I want to learn your way. So, what’s your shortened way ?
Maybe we make use of parse_str() and/or http_build_query() ? I am new to these two functions and are experimenting to learn them. Still struggling. hence, you don;t see any codes here so far. But when I manage to draw up any then I will post here. But in the meanwhile, can you beat me to it ?
Maybe, I get rid of these …
**&& is_string(trim($_REQUEST[‘table’]))
**&& is_string(trim($_REQUEST[‘column’]))