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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:34:23+00:00 2026-05-19T11:34:23+00:00

I have a file go.php on my website that tracks the clicks on certain

  • 0

I have a file go.php on my website that tracks the clicks on certain links and I want to count only the clicks that are made on my website and not on other sites that copy that link (site.com/go.php?id=). I have tried with this code

if($_SERVER[HTTP_REFERER] && !preg_match("/site\.com/", $_SERVER[HTTP_REFERER])) {
    header("Location: http:// www .site.com");
    die();
}

but is not working properly, clicks from other sites are counted. Is there any way to count only the clicks made on my website?


EDIT: I formatted the code, but I left the spaces near http:// and www. -gore

  • 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-19T11:34:24+00:00Added an answer on May 19, 2026 at 11:34 am

    $_SERVER[HTTP_REFERER] is not worth of considering as there is no guarantee that it will be send by the user. Also its value might be modified.

    You could use quite common technique that uses unique tokens:

    //some-file.php:
    $uniqueToken = substr(sha1(uniqid()), 0, 8); // 8-characters long unique token, eg "2fac223a"
    $_SESSION['token'] = $uniqueToken;
    
    // ...
    
    <a href="go.php?id=123&amp;token=<?php echo $uniqueToken ?>">Click here</a>
    
    //go.php:
    if (!isset($_GET['token']) || $_SESSION['token'] !== $_GET['token']) {
        // invalid request
        exit;
    }
    
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP website I'm maintaining and I've confirmed that this worked at
I have a php/action.php. That script creats a file in the folder ../data/myfile.kml. After
I have a website that displays images, the file that displays the image is
I have a PHP file for my website, index.php, which, as it stands on
I have a php-apache website on which I am trying to track download conversions
I'm developing a PHP website that uses url routing. I'd like the site to
I have a website that returns an access_token (i.e. Facebook). The redirect_uri has been
So I have a website that has greate Search Engine rankings, and like 500+
I want to make a multi-lingual website that defaults to English like example.com with
I've been coding php for a while now and have a pretty firm grip

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.