1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

need click tracking script

Discussion in 'PHP' started by jfiler20, Apr 4, 2013.

  1. #1
    i need a script that allows me to display how many times a file is downloaded
    please understand that i want the ability to display that on my site...giving me a script that just counts that on places it in a counter.php file or in a control panel is NO good for me

    i want it like this:
    sxc.hu/category/9001
    see how it lists under each image how many times its been downloaded
    SEMrush
    i couldnt find any script that gives me that ability yet. but hundreds of sites use that.

    any ideas??
     
    jfiler20, Apr 4, 2013 IP
    SEMrush
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,731
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Its not that hard, if you have a script that counts the number of downloads and uses a database to save its data it will be a quick hack into your existing code to add the number of downloads to your site.

    If your php skills are good, it will be a quick thing to implement. If not, you should thinking of hireing someone.
     
    EricBruggema, Apr 4, 2013 IP
  3. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    yes i already have a count scipt with database and it shows me how many clicks each link has, but only in the control panel.
    how do I display that number next to the link on my site??
     
    jfiler20, Apr 5, 2013 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,731
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    175
    #4
    I have no idea, my glass bol is broken :) maby you can show us some of your code?
     
    EricBruggema, Apr 5, 2013 IP
    YoGem likes this.
  5. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    this is my config.php file


    <?php
     
    # config.php
    # SET VARIABLES #################################
     
    # Change your password. Very important!
     
    $password = "";
     
    # Set the full path to this directory with trailing slash /.
     
    $full_path = "C:";
     
    # Set your mysql database information.
     
    $db_name = "";
    $db_user = "";
    $db_host = "";
    $db_password = "";
     
    #
    # END SETTING VARIABLES #################
     
    $mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
     
    if(mysqli_connect_errno())
    {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }
     
    $header_path = $full_path . "header.php";
    $footer_path = $full_path . "footer.php";
     
    ?>
    PHP:
    and this is my go.php page that the link is sent through to track:
    <?php
     
    # go.php
     
    include_once("config.php");
     
    $page = (isset($_SERVER["QUERY_STRING"])) ? urldecode($_SERVER["QUERY_STRING"]):NULL;
     
    if($stmt = $mysqli->prepare("INSERT INTO clicktracker (xpage) VALUES (?)"))
    {
    $stmt->bind_param("s",$page);
    $stmt->execute();
    $stmt->close();
    }
     
    $mysqli->close();
     
    header("Location: $page");
    exit();
     
    ?>
    PHP:
     
    jfiler20, Apr 5, 2013 IP
  6. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,731
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    175
    #6
    I see and the page where you want it to be?
     
    EricBruggema, Apr 5, 2013 IP
  7. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    lets say this is my html page:
    <p>
    <a href="image1a.jpg">
    <img border="0" src="image1.jpg"></a></p>
    <p>downloaded&nbsp;&nbsp; times</p>
    <p>&nbsp;</p>
    <p>
    <a href="image2a.jpg">
    <img src="image2.jpg" ></a></p>
    <p>downloaded&nbsp;&nbsp; times</p>
    HTML:
    so everytime someone downloads image or image2, i want to write under how many times its downloaded
     
    jfiler20, Apr 6, 2013 IP
  8. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,731
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    175
    #8
    I understand, but i need much more! your image are fetched from the database, i need to see that query and alter it so it also combines this table with the table where we can find number of downloads. Then you need to show me the code where php writes the data (template, or piece of php code) and i'll make a little change in there for u.
     
    EricBruggema, Apr 6, 2013 IP
  9. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #9
    ok i have this file as well: index.php
    <?php
     
    # index.php
     
    include_once("config.php");
    include_once("login.php");
     
    if(isset($_GET['delete']))
    {
    $page = urldecode($_GET['delete']);
    $action = htmlspecialchars($_SERVER["PHP_SELF"]);
     
    print <<<ENDHTM
    <p>Are you sure you want to delete? $page</p>
     
    <form method="post" action="$action">
    <p><input type="hidden" name="confirmdelete" value="$page" />
    <input type="submit" value="Delete" />
    <input type="button" value="Cancel" onclick="history.go(-1); return true;" /></p>
    </form>
     
    ENDHTM;
    exit(include_once($footer_path));
    }
     
    if(isset($_POST['confirmdelete']))
    {
    $confirmpage = urldecode($_POST['confirmdelete']);
     
    $stmt = $mysqli->prepare("DELETE FROM clicktracker WHERE xpage = ?");
    $stmt->bind_param("s",$confirmpage);
    $stmt->execute();
    $stmt->close();
    }
     
    function cmp($a, $b)
    {
        if ($a == $b) { return 0; }
     
    return ($a < $b) ? 1 : -1;
    }
     
    $pageArray = array();
     
    $stmt = $mysqli->prepare("SELECT * FROM clicktracker");
    $stmt->execute();
    $stmt->bind_result($xid,$xpage);
     
        while($stmt->fetch())
        {
        array_push($pageArray, $xpage);
        }
     
    $stmt->close();
    $mysqli->close();
     
        $pageArray = array_count_values($pageArray);
     
        print "<table class=\"data\" cellspacing=\"0\">\n";
        print "<tr><td class=\"short gray\">Clicks</td><td class=\"gray\" colspan=\"2\">Page</td></tr>\n";
        uasort($pageArray, "cmp");
     
            foreach($pageArray as $key => $val)
            {
            print "<tr><td class=\"short\">$val</td><td>$key</td><td class=\"short\"><a href=\"?delete=$key\">Delete</a></td></tr>\n";
            }
     
        print "</table>\n";
     
    include_once($footer_path);
     
    ?>
    
    PHP:
    and for the database, I am using mysql which was provided by my host and i installed it from my control panel

    there are like 100s of files in that database, what do you want to see in specific?
     
    jfiler20, Apr 7, 2013 IP
  10. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,731
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    175
    #10
    Lol this is going to take a long time, i want to see the script where you want the extra code to be. So the page where you display all your 'images' are? or downloads?
     
    EricBruggema, Apr 7, 2013 IP
  11. jfiler20

    jfiler20 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #11
    these are the sql queries:

    xid:
    SELECTCOUNT(*)AS`Rows`,`xid`
    FROM`clicktracker`
    GROUPBY`xid`
    ORDERBY`xid`
    LIMIT0,30

    xpage:
    SELECTCOUNT(*)AS`Rows`,`xpage`
    FROM`clicktracker`
    GROUPBY`xpage`
    ORDERBY`xpage`
    LIMIT0,30

    if you want the html page where i have all my downloads....im still not done with it....but i'll upload a rough draft so you can place the code and i'll use it once I'm done with that page.
    the file uploaded is albums.html

    sorry if im not getting it...im still learning :)
     

    Attached Files:

    Last edited: Apr 7, 2013
    jfiler20, Apr 7, 2013 IP
  12. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,731
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    175
    #12
    Normal you can do 2 things to include the number of downloads to a page.

    1. Add it to your query, the query you use to display all the 'downloads' / items on the album page.
    2. You create a extra query based on all ID's from the 'downloads/albums' query and combine it before using the data on the downloads/albums page.

    Its more work then just add a little extra code to your page..
     
    EricBruggema, Apr 7, 2013 IP
  13. tasos55

    tasos55 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #13
    Did you find something ? if not i have a script for you.
     
    tasos55, Apr 8, 2013 IP