Hey there,
Ive got this piece of code on a page that shows after a message is sent. If the user has an access level of 1 they are resricted to only 10 messages per day.
The code is ment to log each time the message sent page is loaded and when the page is loaded 10 times a record is inserted to the database with the users id and the date. everyday the records date that is less than that days is deleted enabling them to use the message sending page again.
BUT. I only just realised that the user who sends say 8 messages today and trys to send 4 tomorrow cant as the session might still be there only allowing them to send 2.
How can i change this little piece of code, or the delete code so that if the user logs in the next day, the message_sent session is removed?
Code on the message sent page [might be a little messy]:
if ($_SESSION['KT_level_iPals'] == 1){
$user = $_SESSION['KT_id_iPals'];
$d = date('Y-m-d');
if ($totalRows_messageLimit == 0) {
if (empty ($_SESSION['message_count'])){
$_SESSION['message_count']=1;
}else{
$_SESSION['message_count']=$_SESSION['message_count']+1;
if ($_SESSION['message_count'] >= 10){
$sql = "INSERT INTO ipals_message_limit VALUES ('$user', '$d')";
mysql_query($sql, $main) or die (mysql_error());
session_unregister('message_count');
}
}
} else {
echo "MESSAGE LIMIT REACHED!";
session_unregister('message_count');
}
}
Code on the check page after users login:
$sql = "DELETE FROM ipals_message_limit WHERE NOW() > l_date";
mysql_query($sql, $main) or die (mysql_error());
any help would be greatly appreciated.
Danny