We are currently performing searches on a Database and returning results in JSON format to use on a Google Maps. The file that we call is named getvenues.php and works great on the server. It accepts a number of parameters and returns the results based on the query.
We then have a separate file that checks to see if there’s a JSON file on the server which contains the results, matches its age against a setting, and then returns the data either from the cache file, or builds a new cache file if it’s too old.
Since there are several thousand possible search options, we only cache single searches (either on a County, Region or Type). The JavaScript always calls our search_cache_builder.php file. If there is more than one search parameter, the file simply gets the contents returned by getvenues.php and serves it up without any caching.
Everything works great except for one particular combination. If a search is run for venue_type=Castle / Fort and venue_name=Leeds Castle, the search_cache_builder.php returns an empty array, even though accessing getvenues.php directly returns the required data.
Here’s a sample of the getvenues.php working with this data > http://dev.weddingvenues.com/lincweb/getvenues.php?type=Castle%20/%20Fort&venue_name=Leeds%20Castle
And here’s what the search_cache_builder.php script returns with an identical search (the address we are sending to is correct) > http://www.weddingvenues.com/search_cache_builder.php?type=castle%20/%20fort&venue_name=Leeds%20Castle
Here’s the code for the search_cache_builder.php file, which relates to this particular query:
$get_string = '?';
foreach($_GET as $key => $value)
{
if($get_string === '?')
{
$get_string .= $key . '=' . $value;
}
else
{
$get_string .= '&' . $key . '=' . $value;
}
}
//$get_string = str_replace(' ', '', $get_string);
// Otherwise, we need to serve up the page as is:
$file_url = GET_VEN_URL . $get_string;
echo file_get_contents($file_url);
Can anyone offer an explanation as to why the search_cache_builder.php file is returning an empty array?
You should
urlencode()your parameter values.In fact, while your getvenues.php receives parameters directly from a browser it behaves OK, ’cause they are correctly urlencoded.
I tried what follows in my computer towards your service and it works: