Hii
something is wrong in code here i put condition that if 24 hours end up and user don’t post he can’t access post page and i apply exit condition. but i found that after completing 24 hours without posting next 24 hours count down time automatic start instead of doing exit what i want to do please see below my code
$query = "SELECT link.dtime as last_post, CONCAT( DATE( NOW() ), ' ', TIME(msn_users.time) ) as period_end
FROM link, msn_users
WHERE link.userid = msn_users.id
AND msn_users.id = $id
ORDER BY link.dtime DESC
LIMIT 1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$canPost = TRUE;
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$period_end = new DateTime($row['period_end']);
$last_post = new DateTime($row['last_post']);
$now = new DateTime();
if ($period_end > $now)
{
$period_start = clone $period_end;
$period_start->sub(new DateInterval('P1D'));
if ($last_post > $period_start) {
$canPost = FALSE;
}
}
elseif ($last_post > $period_end)
{
$canPost = FALSE;
}
}
if ($period_end < $now) {
$period_end->add(new DateInterval('P1D'));
}
$interval = $now->diff($period_end);
if ($canPost)
{
$seconds = ($interval->h * 3600) + ($interval->m) * 60 + $interval->s;
echo 'You have: ' . $seconds . ' seconds left to post in the current period';
if($seconds <= 0)
{
echo "Time Over";
exit;
}
}
else
{
echo 'Sorry, you can only post again in: ' . $interval->format('%H:%I:%S') . ' hours';
}
Please let me know where is the mistake how can i restrict people if they dont post withing last 24 hours time period they can’t post next. Thanks