Welcome Guest, Not a member yet? Register   Sign In
statistic counter error in IE
#1

[eluser]Antoniofu[/eluser]
Hi to all!

I have a problem with codeigniter, please consider that I'm a newbie with this framework. Smile

The problem is this : I created a script to count how many visits has a page, the script I used is this :
Code:
<?php
            $id = $this->uri->segment(2);
            $query = $this->db->get_where('strutture', array('id'=> $id));
            $row = $query->row();
            
        $browser = $this->agent->browser();
    $version = $this->agent->version();
    $referrer = $this->agent->referrer();
    $ip = $this->input->ip_address();
    function GetSistemaOperativo()
{
$os = array(
'Mac'             => 'Mac',
'PPC'             => 'Mac',
'Linux'           => 'Linux',
'Windows NT 5.1'  => 'Windows XP',
'Windows NT 5.0'  => 'Windows 2000',
'Windows NT 4.90' => 'Windows ME',
'Win95'           => 'Windows 95',
'Win98'           => 'Windows 98',
'Windows NT 5.2'  => 'Windows NET',
'WinNT4.0'        => 'Windows NT',
'FreeBSD'         => 'FreeBSD',
'SunOS'           => 'SunOS',
'Irix'            => 'Irix',
'BeOS'            => 'BeOS',
'OS/2'            => 'OS/2',
'AIX'             => 'AIX',
);
foreach($os as $chiave => $valore)
{
if(strpos($_SERVER['HTTP_USER_AGENT'], $chiave))
{
return $valore;
}
}

return 'Altro';
}
$os =  GetSistemaOperativo();
$anno = date("Y");
    $mese = date("m");
    $ora = date("h:i:s");
    $giorno = date("d");
    $settimana = date("l");
    $stats = array(
                   'id_struttura' => $id,
                   'referrer' => $referrer,
                    'ip' => $ip,
                    'browser' => $browser,
                    'browser_version' => $version,
                    'anno' => $anno,
                    'mese' => $mese,
                    'giorno' => $ora,
                    'settimana'=> $settimana,
                    'ora' => $ora,
                    'os' => $os            
                );
          $this->db->insert('stats',$stats);
                
        ?>

As you can see is a simple script that get some parameters from the user and insert in a database.

Now everything go fine, everytime someone visit(or open) the page, a query was sent to a database with the parameters, like browser, os, ip, etc. finally to get the results I need only to count all the results rows from the query. All is based upon the id_struttura, is the common key used to recover the structure from the database.

The scripts works fine but not with IE, everytime the page is refreshed, IE will count it 9 times and not 1.
here's an example :http://www.tuttoturismoweb.com/strutture/66/CALABRIA/Blu-Notte-.html

if you check the page, and refresh it, on the right side (uesta struttura ha ricevuto : n(the count of results) visite.)

but with IE this counter count it 9 times and not 1. I can't understand why.

the structure is simple : a header(called dettagli.php in the folder headers, added with the controller) and a content page , called dettagli.php in the application/views/ folder.

If every time someone visite the page, the insert query insert the parameters in the database, one time, this for all browser, but not for IE, that instead add 9 times. For example : if the counter is 10, if you refresh with IE, the counter will jump to 19.

Can you help me to understand this strange situation?

I hope I explained good, the question is not easy to explain and probably my bad english is not helpful to understand, for this reason I added the source code.

thanks in advantage to all.
#2

[eluser]WanWizard[/eluser]
Where do you call this script? It doesn't have the normal CI structure (which is completely class based).

If you are sure the script is only called once per page request, check your webserver logs, and see which requests it has received (should be 9 for that page request).

Common problems are mistakes in the .htaccess, in combination with missing files that would cause a request to CI.
#3

[eluser]Antoniofu[/eluser]
Hi thanks for respond,

the script is called in the header of the page.

I used a htacces to delete the index.php , here's rules :
Code:
<IfModule mod_rewrite.c>
AddHandler php5-script .php

RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$http://localhost/tuttoturismoweb.com/html/$1 [R 301,L]
    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

in the counter it adds 9 fields the first time you open the page, and always 1 after the first time.

I'm checking the server logs to get the errors, but honestly I can't understand where is the problem.

As you can see I'm not an experted programmer, so the code is not well wrote.

Anyway thanks for you help.
#4

[eluser]WanWizard[/eluser]
Is this line as-is in your .htaccess?
Code:
RewriteRule ^(.*)index.html$http://localhost/tuttoturismoweb.com/html/$1 [R 301,L]
What is the intention of this line?
#5

[eluser]Antoniofu[/eluser]
is to redirect index.html to the default domain, isn't correct?
#6

[eluser]Antoniofu[/eluser]
I'm thinking to store all the parameter in a session cookie, maybe using a cookie this will be read by IE as one request.

Do you think can works this?
#7

[eluser]WanWizard[/eluser]
[quote author="Antoniofu" date="1278977978"]is to redirect index.html to the default domain, isn't correct?[/quote]
I'm missing a space behind the first $:
Code:
RewriteRule ^(.*)index.html$ http://localhost/tuttoturismoweb.com/html/$1 [R 301,L]
And then it rewrites every link ending on 'index.html'. So /get/this/index.html redirects to http://localhost/tuttoturismoweb.com/htm...index.html

The only thing I can think of that can cause multiple requests is if the page contains links to assets (css, js, images) that can not be found or accessed. In that case your rewrite test on file or directory name will fail, and the asset link will be rewritten to index.php, causing a second CI request. So if your page has 8 of these missing images, you end up with 9 CI requests.

To check, set the log_threshold in the config to 4, and add this to the constructor of your controller:
Code:
log_message( 'DEBUG', 'URI requested: '.$_SERVER['REQUEST_URI'] );

this will write the request that CI receives to the log file. See if that helps you find the issue.
#8

[eluser]Antoniofu[/eluser]
SOlved!!

Thanks you so much!!

The error is a missing assets, as you said. Using the log file I found that the url of some images, png used in the lightbox script only for explorer, ws wrong on the css for these images.

So I just correct the Url and now seems that it works. the request are correct now!

Thanks again, I can't resolve this without your help!!
#9

[eluser]WanWizard[/eluser]
Glad to be of help.

Maybe a tip for next time:

Create a folder named 'assets' in the document root, and create in that folder a structure for all your assets (like /assets/js, /assets/css, etc).
Then exclude the entire assets directory from rewriting by adding "RewriteCond $1 !^assets" just before your last rewrite rule.

Put all your site's assets in this folder structure, and you'll never have rewrite issues due to missing assets.




Theme © iAndrew 2016 - Forum software by © MyBB