All pastes #798238 Raw Edit

Unnamed

public text v1 · immutable
#798238 ·published 2007-11-26 18:04 UTC
rendered paste body
                        $counter = file_get_contents("counter.txt");
                        $ip = sprintf("%u", ip2long($_SERVER['REMOTE_ADDR']));
                        mysql_query("DELETE FROM `excalistia_visitors` WHERE UNIX_TIMESTAMP() - `time` > 3600");
                        $result = mysql_query("SELECT count(*) FROM `excalistia_visitors` WHERE `ip` = " . $ip);
                        if (!mysql_result($result, 0)) {
                            $file = fopen("counter.txt", "w");
                            if ($file) {
                                fwrite($file, ++$counter);
                                fclose($file);
                            }
                            mysql_query("INSERT INTO `excalistia_visitors` SET `ip` = " . $ip . ", `time` = UNIX_TIMESTAMP()");
                        }
                        else
                            mysql_query("UPDATE `excalistia_visitors` SET `time` = UNIX_TIMESTAMP() WHERE `ip` = " . $ip);

                        echo $counter;