Jump to content

How to check if 10 minutes passed since last bump?


Joshua F

Recommended Posts

I have a forum script I made that has thread bumping for the thread creator only. I am trying to limit the amout of time the creator can bump to be every 10 minutes.

 

Here's my code.

	list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"'));
if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){
	header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page']."");
} else {
	if($creator == $_SESSION['username']){
		mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."'");
	} else {
		header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page']."");
	}
}

Link to comment
Share on other sites

Is lastbump the field that bumps the thread? I guess it also serves the "date posted" purpose?

"UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump 

 

Also: You're vulnerable to SQL injection and that's a very bad thing. After you read up on the subject, start using functions mysql_real_escape_string and intval.

Link to comment
Share on other sites

Is lastbump the field that bumps the thread? I guess it also serves the "date posted" purpose?

"UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump <= lastbump - INTERVAL 10 MINUTE"

 

Also: You're vulnerable to SQL injection and that's a very bad thing. After you read up on the subject, start using functions mysql_real_escape_string and intval.

 

I do my main programming first, then go over it to prevent injects. But with that, it doesn't display the error if it hasnt been ten minutes or not.

 

Here's my new code.

list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"'));
if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){
	header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page']."");
} else {
	if(getBumpTime($_GET['threadid']) == true){
		if($creator == $_SESSION['username']){
			mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump <= lastbump - INTERVAL 10 MINUTE");
			$message = 'You have successfully bumped <i>'.$title.'.';
		} else {
			header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page']."");
		}
	} else {
		$message = 'You have reached the bump limit - you can only bump one thread every 10 minutes.';
	}
}

 

And here's my getBumpTime function.

function getBumpTime($id){
	list($lastbump) = mysql_fetch_row(mysql_query('SELECT COUNT(id) FROM forum_threads WHERE id="'.$_GET['threadid'].'" && ((TIMESTAMPDIFF(MINUTE, `lastbump`, NOW() ) > 1 ) or `lastbump`="0000-00-00 00:00:00")'));
	if($lastbump == 1){
		return true;
	} else {
		return false;
	}
}

 

I'm also having problems with ordering it by lastbump and lastpost.

Link to comment
Share on other sites

But with that, it doesn't display the error if it hasnt been ten minutes or not.

And how was I supposed to know that would be an issue? It's not like you posted anything that hinted at the idea of showing an error message.

 

Run the query. If mysql_affected_rows() == 1 then it was bumped and if it == 0 then it was not.

 

I'm also having problems with ordering it by lastbump and lastpost.

Ordering what?

Link to comment
Share on other sites

But with that, it doesn't display the error if it hasnt been ten minutes or not.

And how was I supposed to know that would be an issue? It's not like you posted anything that hinted at the idea of showing an error message.

 

Run the query. If mysql_affected_rows() == 1 then it was bumped and if it == 0 then it was not.

 

I'm also having problems with ordering it by lastbump and lastpost.

Ordering what?

 

The query it displays the threads. I can't do bumped = 1 or 0 because it orders the list by lastpost, then It needs to order it by lastbump as well.

Link to comment
Share on other sites

"UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."' AND lastbump <= now() - INTERVAL 10 MINUTE"

 

Should be correct, since lastbump <= lastbump - INTERVAL 10 MINUTE makes no sense as this will always be true regardless if it has been 10 minutes.

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.