$timeout = "240";
if (isset($_COOKIE['zs4d'])) {
if (time() - $_COOKIE["zs4d"] < $timeout){
// No MySQL
} else {
setcookie("zs4d", time());
// Run MySQL
} else {
setcookie("zs4d", time());
// Run MySQL
}
Im trying to reduce mysql connections for my php script. every request to an image or file on my server results in the php script being called, which adds the users ip and time to a mysql table.
if there are 100 images on the site, 100 requests will be made. i want to cut this down, so i decided to set a cookie for the first time a request was made to a file, and then check for the cookie again to determine if another request is neccessary.
How does that code look? Will it work for what im trying to do? Im new to cookies, so if anyone can forsee any bad things happening with that code let me know please..
basically for each request, its going to run thru that code, determining if the mysql should run or not.
However, will cookies still be set for a request to an image or a movie or something? Will that cookie be available for the next image that loads?
Thanks 🙂