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? 

Link to comment
Share on other sites

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" . 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.