Joshua F Posted December 22, 2012 Share Posted December 22, 2012 My problem is if you access the file with the code below directly it will add 2 to `hits` in the table, but if you use image tags and it is displayed on a webpage it does what it should do, which is just add 1 to `hits`. I can not figure out the reason why. I am using a custom database class which uses PDO. <?php if (is_file("./imgs/{$_GET['image']}.png")) { $file = "./imgs/{$_GET['image']}.png"; } else { header( "HTTP/1.0 404 File not found" ); require_once '../errors/404.error'; exit; } require_once '../classes/Database.php'; $db = new Database(array("host" => "127.0.0.1", "user" => "root", "pass" => "", "name" => "test")); $filesize = filesize($file); $filetype = getimagesize($file); $filetype = $filetype['mime']; $db->query("INSERT INTO `snaps` (`image_id`, hits, `first_view`) VALUES (?, 1, ?) ON DUPLICATE KEY UPDATE `hits` = hits+1;")->bind(1, $_GET['image'])->bind(2, time())->execute(); header('Content-Type: ' . $filetype); header('Content-Length: ' . $filesize); readfile($file); Quote Link to comment https://forums.phpfreaks.com/topic/272283-weird-happenings/ Share on other sites More sharing options...
kicken Posted December 22, 2012 Share Posted December 22, 2012 (edited) When you load an image directly, some browsers may end up making the request twice for various reasons. For instance firefox will request it twice under certain conditions to use the image as an icon for the window on the task bar. edit: https://bugzilla.mozilla.org/show_bug.cgi?id=583351 - The firefox bug Edited December 22, 2012 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/272283-weird-happenings/#findComment-1400872 Share on other sites More sharing options...
Joshua F Posted December 22, 2012 Author Share Posted December 22, 2012 That makes a lot of sence, actually. Would there possibly be a way to detect something like that? Quote Link to comment https://forums.phpfreaks.com/topic/272283-weird-happenings/#findComment-1400873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.