Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stats coding problem...

    I am using a stats script on my server to capture info about my site viewers, but where I would like to grab the referred url, it is only capturing the url of the page currently being viewed, and it's not even doing that all that well, because when it displays the url being viewed, it only displays a portion of it.

    The link below is the site I have the stats script installed on. If you click one of the url's under the agent column, it will navigate you to the url where the code snippet is. If you then come back to the stats site and refresh the page, you will see that you have been tracked and that only the url that where you were when tracked was returned, and not the referring url. (i.e. the stats site's url) I would like to also grab the referring url.

    http://imaqeshaq.com/stats/

    Here is the script I am using...

    Code:
    <?php
    
    
        // ------------------------------------------------------------------------ 
        // configuration file
        // ------------------------------------------------------------------------
        
        // **************************************************************** //
        // ATTENTION                                                        //
        // **************************************************************** //
        // $lvc_include_dir must be set in the file with 'new-visitor' call //
        // **************************************************************** //
    
        $ignore_messages = true;
    
        $lvc_config_file = 'config.inc.php3';
    
        include($lvc_include_dir.$lvc_config_file);
      
        
        // ------------------------------------------------------------------------
        // extract agent from $HTTP_USER_AGENT ($agt)
        // ------------------------------------------------------------------------
        function extract_agent($agt)
        {
            global $lvc_agent_max_length;
            global $lvc_agent_versions;
            global $lvc_agent_os;
            global $lvc_other_agt;
    
            if (ereg('MSIE', $agt) && !ereg('Opera', $agt))  // Internet Explorer
            {
                $new_agt = 'IE';
                $agt = strtr($agt, '_', ' ');
    
                for ($cnt = 0, $ok = false; 
                     $cnt < sizeof($lvc_agent_versions['IE']) && !$ok;
                     $cnt++)
                {
                    if ($ok = ereg($lvc_agent_versions['IE'][$cnt], $agt))
                    {
                        $new_agt .= ';'.$lvc_agent_versions['IE'][$cnt];
                        
                        for (@reset($lvc_agent_os['IE']), $ok = false;
                             (list($key, $value) = @each($lvc_agent_os['IE'])) && !$ok;)
                        {
                            if ($ok = ereg($key, $agt))
                                $new_agt .= ';'.$value;
                        }
                    }
                }
        
                if (!$ok) $new_agt = $agt;
            }
            elseif (ereg('Opera', $agt))  // Opera
            {
                $new_agt = 'OP';
    
                for ($cnt = 0, $ok = false; 
                     $cnt < sizeof($lvc_agent_versions['OP']) && !$ok;
                     $cnt++)
                {
                    if ($ok = ereg($lvc_agent_versions['OP'][$cnt], $agt))
                    {
                        $new_agt .= ';'.$lvc_agent_versions['OP'][$cnt];
                        
                        for (@reset($lvc_agent_os['OP']), $ok = false;
                             (list($key, $value) = @each($lvc_agent_os['OP'])) && !$ok;)
                        {
                            if ($ok = ereg($key, $agt))
                                $new_agt .= ';'.$value;
                        }
                    }
                }
        
                if (!$ok) $new_agt = $agt;
            }
            elseif (ereg('Mozilla/4.', $agt)) // Netscape 4.x
            {
                $new_agt = 'NS';
    
                for ($cnt = 0, $ok = false; 
                     $cnt < sizeof($lvc_agent_versions['NS']) && !$ok;
                     $cnt++)
                {
                    if ($ok = ereg($lvc_agent_versions['NS'][$cnt], $agt))
                    {
                        $new_agt .= ';'.$lvc_agent_versions['NS'][$cnt];
                        
                        for (@reset($lvc_agent_os['NS']), $ok = false;
                             (list($key, $value) = @each($lvc_agent_os['NS'])) && !$ok;)
                        {
                            if ($ok = ereg($key, $agt))
                                $new_agt .= ';'.$value;
                        }
                    }
                }
        
                if (!$ok) $new_agt = $agt;
            }
            elseif (ereg('Mozilla/5.0', $agt) && !ereg('Konqueror', $agt)) // NS 6
            {
                $new_agt = 'NS';
        
                for ($cnt = 0, $ok = false; 
                     $cnt < sizeof($lvc_agent_versions['NS6']) && !$ok;
                     $cnt++)
                {
                    if ($ok = ereg($lvc_agent_versions['NS6'][$cnt], $agt))
                    {
                        $new_agt .= ';'.$lvc_agent_versions_2['NS6'][$cnt];
                        
                        for (@reset($lvc_agent_os['NS']), $ok = false;
                             (list($key, $value) = @each($lvc_agent_os['NS'])) && !$ok;)
                        {
                            if ($ok = ereg($key, $agt))
                                $new_agt .= ';'.$value;
                        }
                    }
                }
        
                if (!$ok) $new_agt = $agt;
            }
            else // others
            {
                $new_agt = $agt;
    
                for (@reset($lvc_other_agt), $ok = false;
                     (list($key, $value) = @each($lvc_other_agt)) && !$ok;)
                {
                    if ($ok = ereg($key, $agt))
                        $new_agt = $value;
                }
        
            }
      
            $new_agt = strip_tags($new_agt);
    
            if (strlen($new_agt) > $lvc_agent_max_length)
                $new_agt = substr($new_agt, 0, $lvc_agent_max_length-4).' ...';
    
            return($new_agt);
        }
        // ------------------------------------------------------------------------
    
        // looking for the cookie
        if ($$lvc_cookie_name == '1')
        {
            // this cookie is only on my machines
            $insert = false;
            setcookie($lvc_cookie_name, '1', time() + (3600*100000));
        }
        else
        {
            $insert = true;
    
            // no insertion if referer comes from the site itself
            if (isset($HTTP_REFERER))
            {
                for ($cnt = 0; $cnt < sizeof($lvc_ignore_referers) && $insert; $cnt++)
                {
                    $insert = $insert && (strtolower(substr($HTTP_REFERER, 0, strlen($lvc_ignore_referers[$cnt]))) != $lvc_ignore_referers[$cnt]);
                }
            }
           
            // no insertion for my own machines
            for ($cnt = 0; $cnt < sizeof($lvc_ignore_machines) && $insert; $cnt++)
            {
                $insert = $insert && ($REMOTE_ADDR != $lvc_ignore_machines[$cnt]);
            }
           
            // no insertion if not the good server (test servers for example)
            for ($cnt = 0; $cnt < sizeof($lvc_ignore_servers) && $insert; $cnt++)
            {
                $insert = $insert && ($SERVER_NAME != $lvc_ignore_servers[$cnt]);
            }
        }
    
    
        if ($insert)
        {
            $found = false;
            
            $gDb = new Db;
    
            if ($connected = $gDb->DbConnect($lvc_db_host, $lvc_db_user, $lvc_db_password, $lvc_db_database))
            {
                // does this visitor is in [$lvc_between_2_visits] last visitors ?
                $query = 'SELECT MAX(CODE) FROM '.$lvc_table_visitors;
                if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0)
                {
                    if ($gDb->DbNextRow())
                    {
                        $record = $gDb->Row;
                        $max_code = $record[0];
        
                        $query  = 'SELECT COUNT(CODE) ';
                        $query .= 'FROM '.$lvc_table_visitors.' ';
                        $query .= "WHERE ADDR='".$REMOTE_ADDR."' ";
                        $query .= 'AND CODE BETWEEN '.max(0, $max_code - $lvc_between_2_visits + 1).' AND '.$max_code;
    
                        if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0)
                        {
                            if ($gDb->DbNextRow())
                            {
                                $record = $gDb->Row;
                                $found = ($record[0] > 0);
                            }
                        }
                    }
                }
            }
    
            if (!$found)
            {
                $referer = $HTTP_REFERER;
    
                $url = parse_url( $referer );
                $ref_host = $url['scheme'].'://'.$url['host'].'/';
        
                if ($ref_host == ':///')
                    $ref_host = '';
                elseif ($ref_host == 'news:///' || $ref_host == 'news://news/')
                    $ref_host = 'news:';
    
                $rows_list = 'DATE, ADDR, HOST, AGENT, REFERER, REF_HOST';
        
                $agent = extract_agent($HTTP_USER_AGENT);
    
                $values_list  = "'" . date('Y/m/d H:i')                 . "',"; // DATE
                $values_list .= "'" . $REMOTE_ADDR                      . "',"; // ADDR
                $values_list .= "'" . gethostbyaddr( $REMOTE_ADDR )     . "',"; // HOST
                $values_list .= "'" . $agent                            . "',"; // AGENT
                $values_list .= "'" . AddSlashes(strip_tags($referer))  . "',"; // REFERER
                $values_list .= "'" . AddSlashes(strip_tags($ref_host)) . "'";  // REF_HOST
      
                $query  = 'INSERT INTO '.$lvc_table_visitors.' ('.$rows_list.') VALUES ('.$values_list.')';
        
                if ($connected)
                {
                    $gDb->DbQuery($query);
                }
                else
                {
                    $log_file = @fopen($lvc_log_file, 'a');
                    if ($log_file)
                    {
                        fputs($log_file, $query . ";\n");
                        fclose($log_file);
                    }
                }
            }
        }
    
    ?>
    Can anyone help me?

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    use
    PHP Code:
    $_SERVER["HTTP_REFERER"


  •  

    Posting Permissions

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