Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    counter click unici cookie

    ho scaricato il seguente script da php.html.it

    Codice PHP:
    <?php
    /***************************************************************************
     *                                count.php
     *                            -------------------
     *   begin                : Tuesday, Feb 28, 2006
     *   owner                : AtomicOxide.co.uk - Dave
     *   email                : [email]dave@atomic-network.co.uk[/email]
     *
     *
     ***************************************************************************/

    /***************************************************************************
     *
     *   This program is a free script; you can redistribute it and/or modify
     *   it under the terms of the GNU General Public License as published by
     *   the Free Software Foundation; either version 2 of the License, or
     *   (at your option) any later version.
     *
     ***************************************************************************/

    // Set varibles
    $cookie_ip $_COOKIE['client_ip']; 

    $file "count.txt"// File to hold the views in.
    $line file($file);

    // See if the cookie is already set.
    if(!$cookie_ip) { 

    // If not; set the cookie.
    setcookie("client_ip"$_SERVER['REMOTE_ADDR'] , time()+360000); 

    $line[0]++; // Increase value of file by one...

    // Open the file for writing
    $open fopen($file"w+"); 

    // Write to File.
    fputs($open"$line[0]");
    fclose($open); 


    // See if the cookie IP matches the users IP
    elseif($cookie_ip != $_SERVER['REMOTE_ADDR']){ 
    $line[0]++;
    $open fopen($file"w+"); 
    fputs($open"$line[0]"); 
    fclose($open); 
    }
    $count $line[0]++;
    // Now Display Results.
    ?>
    <center>Unique Page Views: [b]<?php echo $count?>[/b] times

    Made by [url="http://atomicoxide.co.uk"]AtomicOxide.co.uk[/url]

    dovrei far conteggiare la visita nel database al posto del file count.txt:


    Codice PHP:
    $newhits = ($row_p['hits'] * 1) + 1;
        
    $update "update count set hits =" $newhits " where id = "$row_p['id']; 
        
    mysql_query($update,$myconn) or die(mysql_error()); 
    cosa devo aggiungere per fare ciò?

    grazie

  2. #2
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Ho risolto così... però vorrei che per ogni ID mi conteggiasse una visita con ugni indirizzo IP diverso.

    Così com'è ora lo script sia se visualizzo la pagina.php?id=1 che la pagina.php?id=2 mi si blocca contando solo sul primo id=1

    come si può fare?

    Codice PHP:
            // Set varibles
    $cookie_ip $_COOKIE['client_ip'];  

    // See if the cookie is already set.
    if(!$cookie_ip) { 

    // If not; set the cookie.
    setcookie("client_ip"$_SERVER['REMOTE_ADDR'] , time()+360000); 

    $line[0]++; // Increase value of file by one...

        
    $newhits = ($row_p['hits'] * 1) + 1;
        
    $update "update items set hits =" $newhits " where id = "$row_p['id']; 
        
    mysql_query($update,$myconn) or die(mysql_error()); 


    // See if the cookie IP matches the users IP
    elseif($cookie_ip != $_SERVER['REMOTE_ADDR']){ 
    $line[0]++;

    }
    $row_p['hits'] = $line[0]++; 

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Devo mettere un controllo... se l'ID è uguale a quello cliccato (ad es. pagina.php?id=1) non eseguire l'update, se al contrario l'ID è diverso da quello cliccato esegui l'update..
    chi mi dice come inserirlo?

    Grazie

  4. #4
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Nella tabella items sono contenuti i campi id=1 id=2 id=3 etc..
    Se apro la pagina scheda.php?id=1 mi esegue l'update:
    Codice PHP:
    $newhits = ($row_p['hits'] * 1) + 1;
        
    $update "update items set hits =" $newhits " where id = "$row_p['id'];
        
    mysql_query($update,$myconn) or die(mysql_error()); 
    Se apro la pagina scheda.php?id=2 lo script riconosce lo stesso IP client e non mi esegue l'update:

    Codice PHP:
    $newhits = ($row_p['hits'] * 1) + 1;
        
    $update "update items set hits =" $newhits " where id = "$row_p['id'];
        
    mysql_query($update,$myconn) or die(mysql_error()); 
    Dovrei far si che ad ogni pagina con ID diverso mi esegue l'update e ad ogni pagina con ID uguale non la esegue perchè già è stata visitata la pagina con lo stesso ID

  5. #5
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Chi mi da un aiuto gentilmente?

  6. #6
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    up

  7. #7
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    up..

  8. #8
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    up

  9. #9
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    up

  10. #10
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    up help

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.