Results 1 to 17 of 17
  1. #1

    Creating a hit counter

    Hey guys: i plan to make a hit counters hosting type website.

    Basically, a user will signup, and copy and paste teh code onto there website.

    This code will be in javascript so that their server does not need to have php enabled.

    With this script, it will track hits, and when there is a hit, it will transfer a variable (his username/domain website) back to my website, in which case will update the counter in mysql database (stored on my server), etc.

    ------------

    However, before i get started i wish to learn a bit more about how this works. If you guys could give me a few pointers and a quick runthrough, i will better be able to tackle this project.

  2. #2
    I can help you... what info you need?
    I made once something like this
    Hosting: Evolve Romania
    Scripting: Azteck Korp

  3. #3
    PHP Code:
    <?    //free counter count.php
    //this is what gets called as <script type="text/javascript" src="http://www.websitegoodies.com/count.php?uid=5">, for example, to show the counter

        
    $connection mysql_connect("localhost","username","password");
        
    $db mysql_select_db("dbname"$connection);

        
    //pull up their # of visits to display
        
    $sql "SELECT * FROM Count WHERE UID = $uid";
        
    $sql_result mysql_query($sql,$connection);
        
    $count mysql_fetch_array($sql_result);

        
    //display the count
        
    echo "document.write('<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td bgcolor=\"#000000\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td bgcolor=\"$count[BGColor]\"><div align=\"center\"><font face=\"arial\" size=\"1\" color=\"$count[FontColor]\"><B>$count[Count]</font></div></td></tr><tr><td bgcolor=\"#18305A\"><div align=\"center\"><a href=\"http://www.example.com\"><img src=\"http://www.example.com/counterbg.gif\" border=\"0\" alt=\"Free Website Tools\"></a></div></td></tr></table></td></tr></table>')";

        
    //update the count in the database
        
    $num = ++$count[Count];
        
    $sql "UPDATE Count SET Count = $num WHERE UID = $uid";
        
    $sql_result mysql_query($sql,$connection);
        
    ?>
    Last edited by Sheps; 06-07-2004 at 12:14 PM.
    Dan Grossman - dan @ awio.com
    My Blog | Affiliate Program for Web Hosts

  4. #4
    How do i get a variable from a mysql database using javascript, or without using php. Maybe i can retrieve a variable from a php file located on my server?

  5. #5
    Join Date
    Dec 2000
    Location
    East Coast
    Posts
    1,747
    Originally posted by RenderStream
    ... Maybe i can retrieve a variable from a php file located on my server?
    That made no sense to me whatsoever.

    As far as I know, JavaScript doesn't have any ability to connect to a mysql database. JavaScript is a client-side scripting language parsed and executed by a browser.

    Why wouldn't you want to use PHP to retrieve data from a mysql database?

  6. #6
    Join Date
    Aug 2003
    Location
    PA
    Posts
    110
    I believe you are looking for something similar to what google Adsense uses, where they store the information and then send you the ads.

    In your needs, you are allowing someone to copy/paste some javascript into their site somewhere, and then your server takes care of storing the counts, from the ips and the date, and also transmitting the necessary digits, and/or images of numbers that will display the counter.

    If this is correct, let us know so someone can comment further on it.

    Take care

  7. #7
    Basically, i dont want to use php because i want people who run their websites on hosts who do not support PHP (such as geocities or lycos).

    Basically, they copy a few lines of javascript code, and it works.

  8. #8
    The counter still needs to be written in PHP or another server-side language on your end. I gave you a good example. It's taken right from one of my sites, and is how that site actually does it. The end user would paste this one their page:

    <script type="text/javascript" src="http://www.websitegoodies.com/count.php?uid=1"></script>

    Where the UID is their user id; you'd have to write the code for creating counters and generating that code snippet. The end-user just needs javascript, the PHP work is all on my server.
    Dan Grossman - dan @ awio.com
    My Blog | Affiliate Program for Web Hosts

  9. #9
    Join Date
    Aug 2003
    Location
    PA
    Posts
    110
    Dan's the man if you want to use the code in the way you asked for it. This is really the only way to, unless you decide to include some perl coding that they can use on there site(which I believe Perl is on jsut about EVERY server, so there ya go). But just doing a copy/paste with a few lines of code works the way dan has displayed in his above post.

    Like I had stated, this is what google does...jsut makes a link to their servers and extracts the data onto the suers's pages.

    LAter

  10. #10
    Join Date
    Jul 2003
    Location
    NYC
    Posts
    245
    http://www.countercode.com
    Operate Your Own Web Counter/Statistics Service...

    a friend of mine is using it... very nice and smooth!
    ---|| Avurt Inc. - ||---
    www.avurt.com
    Banners, Prints, Graphics, Web sites & Much more

  11. #11
    Hey dan, yeah your code was actually what taught me how to use te script. However, i still have a problem.

    The part where it is echo'ing the javascrip to display the "counter" doesnt work.

    and also, i know i need to use php/mysql, which will be served on my own host.

    thanks for the help thus far guys

  12. #12
    Join Date
    Mar 2004
    Location
    Connecticut, USA
    Posts
    264
    Originally posted by RenderStream
    Basically, i dont want to use php because i want people who run their websites on hosts who do not support PHP (such as geocities or lycos).

    Basically, they copy a few lines of javascript code, and it works.
    Nearly any host, at least any that are worth giving your money to, support PHP. ASP is where you run into problems, but ASP sucks so who cares?

    Java doesn't connect to MYSQL, it doesn't have the ability. That's one of the reasons PHP was developed. People wanted to use Java for their sites, because they liked the ability, but no database functions.
    - Chris
    [email protected]
    www.totalmindblow.com
    www.theundergroundfiles.com

  13. #13
    ASP gets the money though , allthough id agree that php is much much better in terms of functionality.

  14. #14
    Nike, basically the script will track a hit on the clients site, and redirect everything for processing on my own server, which has php.

  15. #15
    EDIT: OK, nevermind i figured it out... i think
    Last edited by RenderStream; 06-03-2004 at 05:40 PM.

  16. #16
    Not enough information to help. Provide the URL of the script so that I can try implementing the JS.
    Dan Grossman - dan @ awio.com
    My Blog | Affiliate Program for Web Hosts

  17. #17
    You can look at demo on our website.
    Statistics Counter Service - counter.rws.com.ua

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •