I'm trying to store recently searched for zip codes in a cookie on the users computer (aka iphone). So I'm making a key-vlue array, containing the zip code as the key and the time stamp for when it was last searched for as the value.
The code I have so far loads the data from the cookie if it exists, unserializes it, then adds the current search to it. At this point you should have an array that contains the current search plus all recent searches. I haven't gotten to the part where you delete old searches yet because just getting to this point doesn't work. I can't figure out why and it's driving me crazy. I can see the cookie is set, but its like it won't get unserialized properly. I'm getting so angry because it should be working. the $recentzips array should just keep growing and growing as you do more and more searches, but all it every shows it the more recent search. BUT this is there it makes me even MORE MAD. Every once in a while, it will work. It will load previous search data, and add on to it, and i'll see two recent searched zip codes on the page. Then next time I search, its broken again. I swear to god i'm ready to ****ing kill someone.
Anyway this is the code:
if (isset($_GET['zipcode']))
{
$data = mysql_query("SELECT * FROM zipcodes WHERE zip='{$_GET['zipcode']}'");
if (mysql_num_rows($data))
{
if (isset($_COOKIE['recentzips']))
{
$recentzips = unserialize($_COOKIE['recentzips']);
}
$recentzips[$_GET['zipcode']] = time();
setcookie("recentzips",serialize($recentzips),time()+31104000,"/",".menulizard.com");
}
}
And this is the page. The easiest way to "do" searches is to just manually type zip codes into the URL. Use valid ones otherwise it won't even try to store them, it is that smart at least.
http://iphone.menulizard.com/byzip/results/?miles=3&zipcode=01801
Any one have a clue what is going on this this thing? Fixing this could save a life!