Visitors statistics script, there is a form on the page and a submit button, how to add a click counter to the script?

function q($v) { return mysql_real_escape_string($v); } if (empty($error) and !empty($_GET['url']) and !stristr($_GET['url'],"escape(document.URL)")) { $offset = 0; @include("offset.php"); $t = time()+3600*$offset; $day = date("D",$t); $dt = date("Ymd",$t); $tm = date("H:i",$t); $refer = $_GET['ref']; $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); $user = $_SERVER['HTTP_USER_AGENT']." [".$_GET['scr']."]"; $r = parse_url($_GET['url']); $req = $r['path'].(!empty($r['query'])?"?".$r['query']:"").(!empty($r['fragment'])?"#".$r['fragment']:""); if ($ip = $_SERVER['HTTP_X_FORWARDED_FOR']) { if (!stristr($_SERVER['HTTP_X_FORWARDED_FOR'],$_SERVER['REMOTE_ADDR']) and !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipu .= ", ".$_SERVER['REMOTE_ADDR']; else $ipu = $_SERVER['REMOTE_ADDR']; $proxy = $_SERVER['REMOTE_ADDR']; } else { $ipu = $_SERVER['REMOTE_ADDR']; $proxy = ""; } if ($proxy == $ipu) $proxy = ""; $a = explode(", ",$ipu); $real_ipu = $a[count($a)-1]; if (!empty($proxy)) $host = gethostbyaddr($proxy); else if ($host = gethostbyaddr($ipu)) ; else if ($host = gethostbyaddr($real_ipu)) ; else $host = $ipu; $fri = mysql_query("INSERT INTO skinb(day,dt,tm,refer,ipu,proxy,host,lang,user,req,city,country) VALUES('".$day."','".$dt."','".$tm."','".q($refer)."','".q($ipu)."','".$proxy."','".$host."','".q($lang)."','".q($user)."','".q($req)."')"); if (!$fri) error_log(strftime("%d.%m.%y %H:%M:%S")." Error: ".mysql_error()."\n", 3, preg_replace("/[^\/]+$/i","",__FILE__)."errors.dat"); mysql_close(); } ?> 

  • Format the code first. It is unreadable. - E_p

1 answer 1

// Pull the current value of the counter from the database into the variable

$ counter = mysql_query ("SELECT count FROM skinb");

// Add 1

$ counter ++;

// Update the count value in the write request

  $fri = mysql_query("INSERT INTO skinb(day,dt,tm,refer,ipu,proxy,host,lang,user,req,city,country,count) VALUES('".$day."','".$dt."','".$tm."','".q($refer)."','".q($ipu)."','".$proxy."','".$host."','".q($lang)."','".q($user)."','".q($req)."','".q($counter)."')"); 

Although why write a bike, if in the same Yandex metric, there is a counter on the button)

  • Thank! Works. - ivanov
  • @ivanov tick the issue resolved then - nueq