-1

I have a site which contains a number of pages, with a hit counter on the Home page. Each time a visitor returns to the Home page the counter is incremented.

I have written some php which decrements the counter when the Home button is clicked but then I can't find a way to go back to the home page.

Is this possible in php?

Thanks.

  • 1
    possible duplicate of http://stackoverflow.com/questions/7467330/php-headerlocation-force-url-change-in-address-bar – DrPrItay Jul 30 '16 at 09:23

1 Answers1

0

What you are trying to do is not possible with only PHP and it would never be waterproof, what if your user is at the home page and refreshes the page x times... ?

What you need to do instead is to wrap your code with a check whether the counter already has been incremented for the specific session. As you did not give your code specifics, here is some pseudo code.

<?php
    session_start();

    if (!isset($_SESSION['counter_incremented'])) {
        /**
           Your current increment code 
       **/
      $_SESSION['counter_incremented'] = true;
    }

do note that the counter will be incremented once per session, meaning if an user closes his browser and returns to the home page, the counter will be incremented again by one

DarkBee
  • 16,592
  • 6
  • 46
  • 58