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

  • Home
  • SEARCH
  • 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 8542459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:04:36+00:00 2026-06-11T12:04:36+00:00

I’m using this method to display different content based on the variable that was

  • 0

I’m using this method to display different content based on the variable that was passed down from my previous page.

    <?php
    if (isset($_GET['click'])) {
        if($_GET['click'] == 'person'){
          file_put_contents('person.txt', ((int) file_get_contents('person.txt')) + 1);
          include 'resultperson.php';
        } elseif ($_GET['click'] == 'text'){
          file_put_contents('text.txt', ((int) file_get_contents('text.txt')) + 1);
          include 'resulttext.php';
        } elseif ($_GET['click'] == 'online'){
          file_put_contents('online.txt', ((int) file_get_contents('online.txt')) + 1);
          include 'resultonline.php';
        }
    } else {
        include 'resulttext.php';
    } 
    ?>  

Problem is, when I hit refresh, the file_put_contents() function will be executed again. It’s just a way that I use to track how many times users have clicked that button.

How do I prevent the increment of the integer being injected upon refreshing the page?

Or if there’s a simpler method doing all this?

  • 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-11T12:04:37+00:00Added an answer on June 11, 2026 at 12:04 pm

    Using a session is probably your best bet, unless you don’t mind that when the user closes the browser and visits the page again it will be triggered.

    // This will be set to true if the user has the session variable set
    $clicked = isset($_SESSION['clicked']);
    
    // Check if get variable 'click' is set, and that $clicked is false. 
    // If 'click is set and $clicked if false, the variable $click is set to the 
    // value of $_GET['click'] (for example 'person'). Other wise it will be set to false.
    $click = (isset($_GET['click']) && !$clicked) ? $_GET['click'] : false;   
    
    // Set the session variable 'clicked' if it isn't set so that the next time 
    // the user visits, we'll know
    if (!$clicked) {
        $_SESSION['clicked'] = 1;
    }
    
    if($click == 'person'){
        file_put_contents('person.txt', ((int) file_get_contents('person.txt')) + 1);
        include 'resultperson.php';
    } elseif ($click == 'text'){
        file_put_contents('text.txt', ((int) file_get_contents('text.txt')) + 1);
        include 'resulttext.php';
    } elseif ($click == 'online'){
        file_put_contents('online.txt', ((int) file_get_contents('online.txt')) + 1);
        include 'resultonline.php';
    } else {
        include 'resulttext.php';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.