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 4236618
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:39:54+00:00 2026-05-21T02:39:54+00:00

I made a hit counter for a web app, but am confused as to

  • 0

I made a hit counter for a web app, but am confused as to why it’s incrementing by two. I simply set a counter variable from the hitCount.txt file, which contains an integer and write the pre-incremented value back to the file.

The code in question:

    // get visit count
    $wag_file = "hitCount.txt";
    $fh = fopen($wag_file, 'r+');
    $wag_visit_count = intval(file_get_contents($wag_file));
    // increment, rewrite, and display visit count
    fputs($fh, ++$wag_visit_count);
    fclose($fh);
    echo $wag_visit_count . $html_br;
  • 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-05-21T02:39:54+00:00Added an answer on May 21, 2026 at 2:39 am

    I’d say the most logical explanation is that your PHP script is called twice.

    Take a look at what’s called by the browser, using for example the Net tab of Firebug.

    A typical example is an <img> tag with an empty src : the browser will consider the empty src points to the current page — and reload the current URL.

    As a sidenote : instead of reading the file and only then writing it back, you should open your file in read/write mode, and lock it, to avoid concurrent writes — see flock().

    Basically, as you are already opening the file in r+ mode, you should use something like fgets() to read from it — and not file_get_contents().

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

Sidebar

Related Questions

I made an iphone app to capture image from camera and to set that
I've made a twitter-like web app. Users can follow one another when viewing eachother's
I've made a basic cart for my web app, I'm just having a hard
I made a simple calculator and Everytime I hit calculate it'll give a an
I made a dll in c# but i need to export the functions. Is
I made a Web service in which I have a function to count some
I made a theme in WordPress which hit the mod_security rule on HostGator and
I made this small program to test parallelization. When I hit button1 several times
i made a small test app with 2 screens. the first screen contains an
I recently made the insanely long overdue switch from tcsh to bash. The only

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.