+ Reply to Thread
Results 1 to 3 of 3

Thread: Hit Counter.

  1. #1
    tpounds is offline x10Hosting Member tpounds is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    36

    Hit Counter.

    I need help on inserting a hit counter on Dreamweaver. I need to know how many people have gone to my site.

    Please help me with the script, or give me one. I don't know PHP D:

    Join SohailTech.com today!

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Hit Counter.

    i don't know if you're gonna be using mysql or a file to count the users, but i'll post below. the mysql one is assuming you've already got a connection open.

    PHP Code:
    <?php
    // Hit counter stored to file

    $loc '/home/username/counter.txt';
    $fp fopen ($loc'w+');
    $hits fread ($fpfilesize($loc));
    $hits++;
    fwrite ($fp$hits);
    fclose ($fp);

    echo 
    'Hits: ',$hits;

    ?>
    PHP Code:
    <?php
    // Hit counter stored to database

    list($hits) = mysql_fetch_row(mysql_query('SELECT hits FROM counter');
    $hits++;
    mysql_query('UPDATE counter SET hits=\''.$hits.'\' LIMIT 1');

    echo 
    'Hits: ',$hits;
    ?>

  3. #3
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: Hit Counter.

    I Use a hit counter but also visitor history, which tells me more about each visit: stored to MySQL(Table 'LOG'), so that I can report on it.

    This is the php file "sniffer.php" which I put into an incude folder.

    You'll have to put in your own connection and database selection.

    PHP Code:
    <!--Sniffer Script -->
    <?php require_once ($_SERVER["DOCUMENT_ROOT"].'/Connections/freecrm.php'); ?>
    <?php 
    //connection
    //database selection

          
    <?php
          $userloggedin
    =$HTTP_SESSION_VARS['MM_Username'];//take username from session if you are using it.
          
    $ip=$_SERVER['REMOTE_ADDR'];//get ip address
          
    $when time();//get time page was hit
        
    $clientbrowser getenv(HTTP_USER_AGENT);//get system and browser info
        
    $referer getenv(HTTP_REFERER);// get refering page i.e. where it came from
            
    function getAddress()
            {
            
    $protocol $_SERVER['HTTPS'] == 'on' 'https' 'http';
            return 
    $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            }
        
    $clienturl=getAddress();//call address function above to get URL visited
        
    $clienthost=gethostbyaddr($_SERVER['REMOTE_ADDR']);//get hostname
        
    $clientlanguage=$_SERVER["HTTP_ACCEPT_LANGUAGE"];// get language
        
    ?>
    <!--end sniffer script -->
    <!--Start of sniffer insert -->
        <?php
        mysql_query
    ("
        INSERT INTO LOG (IP, BROWSER, VISDATETIME, REFERAL, URL, LANGUAGE, HOST) VALUES('
    $ip', '$clientbrowser', '$when', '$referer', '$clienturl' ,'$clientlanguage', '$clienthost')
        "
    ) or die(mysql_error()); //insert record into db
        
    ?>
    <!--End of sniffer insert -->
    When this is saved, just include this in every page you want to track. (I put it into a header include so its always on every page I put a header into.)

    PHP Code:
    <?php include("sniffer.php");?>
    You can then have a report page to echo this data however you want. It also tracks bots.

+ Reply to Thread

Similar Threads

  1. Flash Counter
    By satheesh in forum Off Topic
    Replies: 6
    Last Post: 02-17-2008, 10:02 AM
  2. Question about counter things
    By galaxyAbstractor in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 11-25-2007, 05:28 AM
  3. Animation Flash Counter for 15 Credits.
    By satheesh in forum The Marketplace
    Replies: 2
    Last Post: 10-02-2007, 10:13 PM
  4. Replies: 17
    Last Post: 01-17-2007, 04:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers