Jump to content

Suggestion on how to limit action upon login


sac0o01

Recommended Posts

So I have an application that allows users to earn points after logging in and visiting their account page using the following:

 

$addviews = mysql_query("UPDATE users SET viewlimit = viewlimit + 100 WHERE user_id = '".$_SESSION['userId'] . "' ");

 

This works fine except that by simply refreshing the page the user will gain another 100 points, and on and on....

 

What would be a simple way to only award the points once a day? 

Yes, good thinking.  Hadn't thought of that.  Would be rather simple to do.

 

Actually I had just came up with this:

 

$dailylimit = mysql_query("SELECT lastvisit FROM users WHERE user_id = '{$_SESSION['userId']}' ");
$dlrow = mysql_fetch_row($dailylimit);
$lastvisitdate = $dlrow[0]; 


$todaysdate = date("Y-m-d");
if($lastvisitdate != $todaysdate)
{
$addviews = mysql_query("UPDATE users SET viewlimit = viewlimit + 100 WHERE user_id = '".$_SESSION['userId'] . "' ");
}

 

Just have to make sure the code is executed before the query is sent to update "lastvisit" . 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.