okay, i had a bash at making a simple PHP counter and it erm didnt work.
okay heres what i have.
PHP Code:
<?php include('includes/includes.php'); $ip = $_SERVER['REMOTE_ADDR']; $useR_agent = $_SERVER['HTTP_USER_AGENT']; $result = mysql_query("SELECT * FROM counter WHERE ip='$ip'") or die("ERROR select check if exist".mysql_error()); $user_count = mysql_fetch_array($result); $row_num = mysql_num_rows($result); if($row_num = 1) { $user_count = $user_count['visit_count']++; mysql_query("UPDATE counter SET visit_count='$user_count' WHERE ip='$ip'") or die("ERROR updateing".mysql_error());
$result_count = mysql_query("SELECT COUNT(*) FROM counter") or die("ERROR select count 1".mysql_error()); $count=mysql_result($result_count, 0); echo $count; }
else { mysql_query("INSERT INTO counter SET ip='$ip',visit_count='1',user_id='0',user_agent='$user_agent'") or die("ERROR inserting".mysql_error()); $result_count = mysql_query("SELECT COUNT(*) FROM counter") or die("ERROR select count 2".mysql_error()); $count=mysql_result($result_count, 0); echo $count; } ?>
the first include has the database connection...
basically the idea is on load it checks if theres a entry for ip if yes increments
"visit_count" by 1 and echos the total unique visitors.
if there isnt a entry it inserts the users ip and their user agent info (to try and help me see the stats for visitors.) and gives them a visit_count of 1
and then echos total unique visits.
how can i better do this?
i would like it so like many counters it isnt effective if a user sits and refreshes the page
i would like it so it only counts and adds one to users visit count for each time of opening the site if you get me?
i have just confused myself now yet alone you lot!
Dan
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|