Single click counter in php with 12-hour time

Asked

Viewed 73 times

0

Hello, I’m trying to create a click counter that records a log in the database to record the visitor’s IP so that when he clicks the link the click counter only records if he clicked after 12 hours of the last click and he gave the same link.

in the database I already have the table log_clicks

no banco de dados já tenho a tabela log_clicks

My PHP code this way, it is already recording the uid which would be the link id, ip and the time() + 60*60*12 that it would be 12 hours ahead to then do the if(time() > $row_rsClicks['**time']) that tbm is already working right.

What I need now is to know how to do so that I check in the table log_clicks if the IP already clicked on the link with the uid X if yes then it checks if when it clicked already past 12 hours if it has already passed then record another log.

My idea is to make this click counter like this site https://www.gamestop200.com/ where your click is added to only after 12 hours.

$colname_rsClicks = "-1";
if (isset($_GET['uid'])) {
  $colname_rsClicks = $_GET['uid'];
}
mysql_select_db($database_connectDB, $connectDB);
$query_rsClicks = sprintf("SELECT * FROM log_clicks WHERE site_uid = %s", GetSQLValueString($colname_rsClicks, "int"));
$rsClicks = mysql_query($query_rsClicks, $connectDB) or die(mysql_error());
$row_rsClicks = mysql_fetch_assoc($rsClicks);
$totalRows_rsClicks = mysql_num_rows($rsClicks);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if (isset($_GET["uid"])) {
    if(time() > $row_rsClicks['time']){
  $insertSQL = sprintf("INSERT INTO log_clicks (site_uid, time, ip) VALUES (%s, %s, %s)",
                       GetSQLValueString($_GET['uid'], "text"),
                       GetSQLValueString(time() + 60*60*12, "int"),
                       GetSQLValueString($_SERVER['REMOTE_ADDR'], "text"));

  mysql_select_db($database_connectDB, $connectDB);
  $Result1 = mysql_query($insertSQL, $connectDB) or die(mysql_error());

  $insertGoTo = "/";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
}

echo $totalRows_rsClicks;
mysql_free_result($rsClicks);

1 answer

0

You have link ID, user IP.

Then at the first click of the user on a link, you increase the click to 1, and arrow a field proximo_click = current time + 12.

When the user clicks on the link you check, is there already this IP registered for this link ID? If so, do you check, the current time is greater or equal to the next field_click ? If so, you increase by one click, if negative you do not increase.

You can have a table, with the fields, ID_LINK, IP, CLICKS, NEXT_CLICK... SELECT * WHERE ID_LINK="link_clicked" AND IP="current_user_ip".....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.