View Single Post
  #4  
Old 02-21-2009, 05:34 AM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vbplusme View Post
I think you might need to use a javascript function to get were you want to go.
That would require a user to stay on the page for 10 minutes and not navigate away. Very not cool from a design standpoint.

Quote:
Originally Posted by Vaupell View Post
A user clicks a botton / or another event happens that triggers a timestamp to be marked.
Very easy to add a timestamp to a database.

Quote:
Originally Posted by Vaupell View Post
how would i go about counting 10 minuttes, and activate a trigger after
those 10 minuttes ?
Not very easy to make a "trigger" after 10 minutes. You might consider using what's known as a CRON job. CRON jobs are scripts that get executed every 5/10/15/30/60/1440 minutes. There's no real way to guarantee that the trigger will be executed exactly 10 minutes after someone sets the timestamp - the cron job will just run at the set intervals. So if someone initaties the trigger right before your cron job runs - then the script will pass them over since it hasn't been 10 minutes for them. They may have to wait 12 minutes, or even 15... All the way up to 19 minutes for the next cron job script to come along and unset the delay.

Quote:
Originally Posted by Vaupell View Post
sort of a delay, and perhaps ewen if the user hits refresh
the display would just show something like 5minuttes togo.
Okay, hang on. Do you want a trigger or do you just want a delay? Because delays are much easier...

Say you've got a table in the database called "delay_timestamps"... It would have the fields "userid" and "timestamp".

Insert or update the field with the user like so
PHP Code:
$db->query_write("INSERT INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() );
// or...
$db->query_write("UPDATE ".TABLE_PREFIX."delay_timestamps SET timestamp=".time()." WHERE userid=".$userid );


// OR even better - this handles insert and update in 1 SQL statement
// but you have to set the userid field in the table as the key
// shouldn't be a problem since userids should be unique anyway

$db->query_write("INSERT ON DUPLICATE KEY UPDATE INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() ); 
Then in your "refresh" page you'll want to have a look see at the timestamp in the database and compare it with the current time:

PHP Code:
$wait_time 5// set the wait time they have before accessing the page again

$current_time time();

$user_timestamp $db->query_first("SELECT timestamp FROM ".TABLE_PREFIX."delay_timestamps WHERE userid=".$userid );

$number_of_seconds_since_stamp $current_time $user_timestamp;

$minutes_since_timestamp $number_of_seconds_since_stamp 60;

if(
$minutes_since_timestamp $wait_time)
{
     echo 
'Sorry, you still have '$wait_time-$minutes_since_timestamp .' minutes left...';
}
else
{
     echo 
'How sweet, you waited for me!';


This, of course, isn't the exact code you'll want... Certainly you'll want to condense the code down, like the $number_of_seconds_since_stamp variable is totally worthless - you can just divide by 60 on the fly. The timestamp variable in the database should probably be of type INTEGER, be careful not to use something like SMALLINT because it's not big enough for the timestamp. However, this will require an action from your user - it's not a trigger. It will require the user to click refresh, or to view the page again in some way.

You might be able to work out some AJAX thing that starts up on every single page that checks for the time remaining and then starts an auto-refresh count down... But it'd be kinda wasteful in my opinion. Plus, some browsers disable the javascript redirects/refreshes.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01297 seconds
  • Memory Usage 1,797KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete