Click counter
Publié le 13 juillet 2015 | Par adminblog | Commenter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php /* Name: hits counter Description:it's a simple hit counter which keeps track your visitor to the site ,it also keeps count of the perticular ip and its count,it also keeps the last visited page */ ## before using this code you must make the following table in your database #Table name: stats # fields: Ipaddress(varchar(150)),host(varchar(150)),browser(varchar(150)),referer(varchar(150)),filename(varchar(150)). # table name: hits # fields: ipaddress(varchar(150)),count(int(11)) ############################################### global $dblink,$PHP_SELF; $ip = getenv("REMOTE_ADDR"); $host = getenv("HTTP_HOST"); $browser = getenv("HTTP_USER_AGENT"); $referer = getenv("HTTP_REFERER"); $sql = "SELECT ipaddress FROM stats WHERE ipaddress = '$ip'"; #### TO DO ###################### # make the connection to your database here $result = @mysql_query($sql, $dblink); $num = mysql_num_rows($result); if( $num == 0 ) { $sql ="INSERT INTO stats(ipaddress,host,browser,referer,filename) VALUES('$ip', '$host', '$browser', '$referer','$PHP_SELF')"; $result=mysql_query($sql,$dblink); $sql1="INSERT INTO hits(ipaddress,count) VALUES('$ip',1)"; $result1=@mysql_query($sql1,$dblink); $text="you had a new visitor from IP: $ip, Host: $host Browser: $browser Referer: $referer"; if ($result) { mail("abc@abc.com", "You had a new visitor",$text, "FROM: stats@abc.com"); } }else{ $sql = "UPDATE hits SET count = count + 1 where ipaddress='$ip'"; $result =@mysql_query($sql, $dblink) ; $sql2 = "UPDATE stats SET filename ='$PHP_SELF' where ipaddress='$ip'"; $result2 =@mysql_query($sql2, $dblink) ; } ?> |
Commentaires récents