/    Sign up×
Community /Pin to ProfileBookmark

Link Clicks

I want to keep track of how many times a link is clicked and display this to a users, it’ll help determine what’s a great read. So not a 1990’s visitor counter.

Last time I tried something similar is doing

refer.php?linkID=$$$

Then look up the ID in a database, increment the counter field by 1 before getting the URL and redirecting the user.

The issue was robots used to increase it by one all the time and it wasn’t realistic.

What’s the best practice way of doing something like this?

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@daveyerwinJul 04.2020 — are you in control of the link target ?
Copy linkTweet thisAlerts:
@kiwisauthorJul 04.2020 — @DaveyErwin#1620233

No.
Copy linkTweet thisAlerts:
@daveyerwinJul 04.2020 — @kiwis80#1620243

humans could click the link all they wanted to

and never read the article
Copy linkTweet thisAlerts:
@NachfolgerJul 05.2020 — Building your own analytics is a joke. Take a look at https://analytics.google.com
Copy linkTweet thisAlerts:
@kiwisauthorJul 05.2020 — A couple of things here.

  • * I'm not bothered if people click the article and not read it. I don't anticipate miss use and the effect is someone did would be minor and not worth the time.

  • * it's also not an analytics tool.


  • I was simply going to have a list of news headlines and somewhere around the DIV container of the headline I was going to have a binoculars icon with the number of "views". A simply guide of how popular the link it.

    The current issue is robots will make my counter go up.
    Copy linkTweet thisAlerts:
    @daveyerwinJul 05.2020 — search engine bots don't push buttons

    black hat bots push buttons

    you are not likely to be visited

    by the black hats
    Copy linkTweet thisAlerts:
    @NogDogJul 05.2020 — You could look at $_SERVER['HTTP_USER_AGENT'] and do some best guessing at whether or not the request is from a robot. It's by no means 100% guaranteed, but some googling would probably give you a decent list of things to look for in the user agent header to identify the most common bots.
    Copy linkTweet thisAlerts:
    @kiwisauthorJul 05.2020 — @DaveyErwin#1620254 that's incorrect, I've previously had counters from the IP address of google bots and many other safe bots.

    They may not push buttons but they find the URL and crawl through it..
    Copy linkTweet thisAlerts:
    @daveyerwinJul 05.2020 — in a previous post @kiwis80#1620256 said ...

    Then look up the ID in a database, increment the counter field

    by 1 before getting the URL and redirecting the user.

    @kiwis80#1620256 said ...

    "I've previously had counters from the IP address of google bots and many other safe bots.

    They may not push buttons but they find the URL and crawl through it.."


    Right

    exactly my point

    use buttons to initiate server action

    no urls on webpage

    nothing to crawl

    urls on server in database
    Copy linkTweet thisAlerts:
    @kiwisauthorJul 05.2020 — @DaveyErwin#1620257

    Are are you suggesting I make the hyperlink a button but made to look like URL with CSS?

    making the button link to the URL via Javascript
    Copy linkTweet thisAlerts:
    @daveyerwinJul 05.2020 — @kiwis80#1620260 said ...

    "Are are you suggesting I make the hyperlink a button

    but made to look like URL with CSS?

    making the button link to the URL via Javascript"

    no

    in a previous post kiwis80 said ...

    "Then look up the ID in a database, increment the counter field

    by 1 before getting the URL and redirecting the user."

    you can redirect from server with

    a url stored in database after you

    increment the counter field

    one button per target url

    or a select element populated with

    identifiers associated with url

    or an input element for the user to

    actually type in the url
    Copy linkTweet thisAlerts:
    @kiwisauthorJul 07.2020 — @DaveyErwin#1620262 To be honest this makes no sense? I'm wondering if we are confusing each other. This is my DB table

    RowID, LinkURL, LinkName, ClickedCnt

    1 http://www.google.com Google 122

    2 http://www.yahoo.com Yahoo 154

    On my index.php page I have <a href="link.php?ID=2">Yahoo</a>

    My question is on link.php page. Here I find the LinkURL from my database, update the ClickedCnt by increasing it by 1 then redirect my user via header or JS to the LinkURL. The problem is robots will follow this link from my index.php page.
    Copy linkTweet thisAlerts:
    @daveyerwinJul 07.2020 — ``<i>
    </i>&lt;form action="link.php" method="post"&gt;
    &lt;select name="select1"&gt;
    &lt;option value="1"&gt;Google&lt;/option&gt;
    &lt;option value="2"&gt;Yahoo&lt;/option&gt;
    &lt;/select&gt;
    &lt;button&gt; Submit &lt;/button&gt;
    &lt;/form&gt;<i>
    </i>
    `</CODE>

    link.php
    <CODE>
    `<i>
    </i>&lt;?php
    if(isset($_POST['select1'])){
    $select1 = $_POST['select1'];
    switch ($select1) {
    case '1':
    $ID = 1;
    break;
    case '2':
    $ID = 2;
    break;
    default:
    break;
    }
    echo $ID;
    }
    ?&gt;<i>
    </i>
    ``
    ×

    Success!

    Help @kiwis spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.7,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...