Inhits counting in php

Discussion in 'PHP' started by khan11, Sep 30, 2007.

  1. #1
    Hello guys!!


    I want to know that how can we get counting numbers like which site is referring us the most?
    for example:

    5 sites have linked to us and i linked to them:

    so, on my page i have shown:
    sitea.com {inhits: 4}
    siteb.com {inhits: 1}
    up to so on


    i hope you get it..

    any solution?
     
    khan11, Sep 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    
    if (isset($_SERVER['HTTP_REFERER']) AND $referer = @parse_url($_SERVER['HTTP_REFERER']))
    {
        $referer['host'] = mysql_real_escape_string($referer['host']);
        
        mysql_query("
            UPDATE table_name
            SET hits = hits + 1
            WHERE hostname = '" . $referer['host'] . "'
            LIMIT 1
        ") OR die(mysql_error());
    
        if (!mysql_affected_rows())
        {
            mysql_query("
                INSERT INTO table_name
                   (hostname)
                VALUES
                    ('" . $referer['host'] . "')
            ") OR die(mysql_error());
        }
    }
    
    ?>
    
    PHP:

    Raw, untested example.
     
    nico_swd, Sep 30, 2007 IP
  3. khan11

    khan11 Active Member

    Messages:
    615
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    well thanks for code, but i don't know even a b c of mysql. First i want to know more in php.

    I think we can also give some write command to put it in a text as counter.

    Cant u write a code which stores the inhits in a text file? and we call it from that file?
    or please tell me how can i implement the above code in my page..
     
    khan11, Sep 30, 2007 IP