Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8353881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:23:29+00:00 2026-06-09T09:23:29+00:00

I couldn’t find a succinct way to summarise the question in the title, allow

  • 0

I couldn’t find a succinct way to summarise the question in the title, allow me to elaborate:

I have a website that uses a PHP script “getImg.php” that takes an image binary object from my database and display it when called by the HTML img tag on a separate page.

I would like to log the number of times people view images so I added a simple line to increment the ‘views’ property for the appropriate image.

I thought this would be simple, but it turns out that it increments twice. My bodgy way around this was to make the ‘views’ column a float and increment by 0.5 to result with a 1 increment. However, I viewed my database today to find 0.5 in some images!

When I comment out the end print it works properly. I assumed the call from the HTML tag plus the script itself counts for two calls? But this doesn’t seem to be the case with other people.

Is this just my set up?

<?php

# Connect to db
include('db.php');

# Get ID
$id = $_GET['id'];
if(!is_numeric($id)) exit;

$q = $db->prepare("SELECT tNail,image,format FROM gallery WHERE id = '$id'");
$q->execute();
$row = $q->fetch(PDO::FETCH_ASSOC);

if(array_key_exists("thumb", $_GET))
    $img = base64_decode($row["tNail"]);
else
{
    $img = base64_decode($row["image"]);

    # Add to views if not thumb
    // 0.5 because script called twice due to print?
    $db->query("UPDATE gallery SET views = (views + 0.5) WHERE id = '$id'");
}

switch($row["format"])
{
    case ".jpg":
        header("Content-type: image/jpeg");
        break;
    case ".png":
        header("Content-type: image/png");
        break;
}

print $img;

?>

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:23:30+00:00Added an answer on June 9, 2026 at 9:23 am

    This seems to be a brwoser issue. Browsers like Chrome could prefetch the images so it is loaded once and if the user clicks on a link to a image – it is loaded twice.

    Check:

    Load a image with your browser and then check your apache access.log and if you see 2 request at the same time it is a browser issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I couldn't think of a way to word the title, so sorry for that,
Couldn't find an answer to this one. I have a WPF ListView control that
I couldn't find anything similar to this anywhere. I have an array of pointers
I couldn't find this in the documentation. If I have a complex object in
I couldn't find a suitable title for this. I'm going to express my query
I couldn't find a straight answer to my question and need to know it
Couldn't find similar enough question so I'll ask. I'm trying to use facebook log-in
Couldn't find a trace of the source code behind the Photos application that runs
Couldn't think of a more appropriate question title, but I'm looking for some advice
Sorry couldn't think of a better title. :) Here goes, I have been pulling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.