Link counter - no external page using JS onClick () or another solution in PHP + MySql [closed]

-2

Hello, I'm looking for help to set up a link counter. I would not like to use a page that collects, 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 feature would take this value (link02.php) and put it in a variable.

    
asked by anonymous 26.10.2015 / 02:36

1 answer

1

You can do the clicker listener with jQuery:

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

In order to avoid blocking the user's browsing, you should save the database 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) {

        }
    });
});
    
26.10.2015 / 03:28