www.emilbak.com



User: Pass:    rss

Capturing Click Data

Capturing click data is useful when you want to look at trends such as pages that are looked at the most, or amount of traffic.

To do this you would need to call the function below each time a page is loaded to capture the click data such as user ip, page title and url. Ofcourse you can capture more info here, for example date.
Further on you would need to save the click data in a database or text file (for example a csv file ready to be viewed in excel).

    function saveClickData($pageTitle){
        //try and get the ip of the client.
        $ip ="";
        if ( isset($_SERVER["REMOTE_ADDR"]) )    {
             $ip = '' . $_SERVER["REMOTE_ADDR"] . ' ';
        } else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    {
             $ip =  '' . $_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
        } else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    {
             $ip =  '' . $_SERVER["HTTP_CLIENT_IP"] . ' ';
        }
        $link = $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
    }