setting up a database for tracking which users have clicked which links?

后端 未结 3 1527
野性不改
野性不改 2021-01-11 23:20

I\'ll try and elaborate on my problem a bit more.

I recently got an entry-level part time developer position with my university, in efforts to sharpen my dev skills.

相关标签:
3条回答
  • 2021-01-11 23:32

    you need for example a table "users: id, name, etc..." and a table "clicks: user_id, url".

    to track link clicks you could do something like this:

    <a hreF="log_click.php?url=<?php echo urlencode("some_url?some=param&etc=anything"); ?>">
    

    log_click.php

    <?php
    $url = $_GET['url'];
    $user = /* ie. $_SESSION['user_id'] */
    /* insert to database */
    header('Location: '. $url); // maybe need urldecode($url) here
    exit;
    ?>
    
    0 讨论(0)
  • 2021-01-11 23:37

    Interesting project. You should extract the user from the current accesed page and store in a visited pages log (within the database) for each user.

    0 讨论(0)
  • 2021-01-11 23:39

    You could simply make a PHP script that would retrieve the requested link for them, while also adding a value to MySQL.

    If I were going to do this, I'd probably do something like this:

    <a href="getResource.php?res=video1.mpg&type=video">Video 1</a>
    

    And in PHP, I'd simply get the resource, type and the userid from the session, put them into the database, then retrieve the resource they were looking for. To track if they watched the video the entire way through, you could use javascript to watch for the event of the player coming to an end, then just use a skin that doesn't have a scrub bar.

    0 讨论(0)
提交回复
热议问题