Link counter - no external page, using JS onClick() or other solution in PHP + Mysql

Asked

Viewed 121 times

-3

Hello, I seek help to assemble a link counter. I would not like to use a collection page but rather a solution that runs on any page. Example on a page with 03 links: link01.php, link02.php (which was clicked) and link03.php, now that 02 was clicked, this resource would take this value (link02.php) and put in a variable.

1 answer

1

You can do the click system with jQuery:

$('a').on('click', function(){
    alert(this.href);
});

but for there to be no blocking of the Voce user’s navigation you must save to the bank in an ajax call:

 $('a').on('click', function(){
    var href = this.href;
    $.ajax({
        type: 'get',
        url: 'contador.php?href='+href,                        
        contentType: 'application/x-www-form-urlencoded',
        success: function(response) {

        },
        error: function(xhr, error) {

        }
    });
});
  • Hello @marcelobns, I checked that there is a link counter.php in your code, I should have a page where all links will go through it? Sorry, it’s not clear to me, thanks for the return.

  • @Eduardocorreia the counter.php will be where you will save in your bank the link that was clicked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.