$ip = getenv("REMOTE_ADDR"); //ipアドレス取得 $browseros = getenv("HTTP_USER_AGENT"); //ブラウザとosを取得 $host = gethostbyaddr($ip); //取得したipアドレスからホスト名を取得 $today = getdate(); //時間を取得 $year = $today["year"]; //年を取得 $month = $today["mon"]; //月を取得 $day = $today["mday"]; //日を取得 $hour = $today["hours"]; //時間を取得 $minute = $today["minutes"]; //分を取得 $second = $today["seconds"]; //秒を取得 $weekday = $today["weekday"]; //曜日を取得 require_once 'DB.php'; $db =& DB::connect('pgsql://postgres:postgres@localhost/mycounter'); if (DB::isError($db)) { die($db->getMessage()); } $res =& $db->query("select no,ip,pageid from access order by no desc limit 1"); while ($row =& $res->fetchRow()) { $no_from_db=$row[0]; $ip_from_db=$row[1]; $pageid_from_db=$row[2]; } if(($ip<>$ip_from_db)or(($ip==$ip_from_db)and($pageid_from_db<>$pageid))){ $no_insert="$no_from_db"+"1"; $table_name = 'access'; $table_fields = array('no','year','month','day','hour','minute','second','weekday','host','ip','browseros','pageid'); $sth = $db->autoPrepare($table_name, $table_fields, DB_AUTOQUERY_INSERT); if (DB::isError($sth)) { die($sth->getMessage()); } $table_values = array($no_insert,$year,$month,$day,$hour,$minute,$second,$weekday,$host,$ip,$browseros,$pageid); $res =& $db->execute($sth, $table_values); if (DB::isError($res)) { die($res->getMessage()); } } ?>