Current location: Hot Scripts Forums » General Community » Script Requests » Add to timer without Javascript?


Add to timer without Javascript?

Reply
  #1 (permalink)  
Old 05-03-09, 08:51 PM
PopSmith PopSmith is offline
Newbie Coder
 
Join Date: May 2009
Posts: 18
Thanks: 5
Thanked 0 Times in 0 Posts
Add to timer without Javascript?

First, I am not sure if what I am looking to do is even possible.

I have an idea in my head (and on paper) for an auction site that needs multiple, independent timers.

What I believe to be the trickiest part of what I am looking to do, and the reason I don't think it's possible, at least without JavaScript, is I want the timer to reset itself to 20 seconds when someone bids unless it is currently at a greater time.

Basically, if the timer is at anything greater than 20 seconds and someone bids the timer does nothing, if the timer is at anything less than 20 seconds when someone bids it resets itself to 20 seconds. I have seen examples of sites similar to my idea, but they all use JavaScript for the timers without any "backup" in case the user doesn't have JavaScript enabled.

If it is possible I would like to have it setup where the timers do not rely on JavaScript (or Java), or at the very least have a reliable alternative, so that if a user can't or doesn't want to enable JavaScript they can still participate on the site.

The only reason I am not even sure this is possible is that I can't find any examples of this idea, either paid or free, anywhere on the web.

Also, in case it matters, I plan on coding the site using PHP because I like the way you can dynamically change the site a lot easier than other languages. I am not set on using PHP, however, especially if another coding language would be more "appropriate" for what I am trying to do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-03-09, 11:04 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You could use PHP to run timeouts, by checking the session time on the last request to determine if the person responded before the duration timed out.

PHP Code:

if (isset($_SESSION['last_request']))

{
  
$t20ago=time()-20;  /* Time 20 seconds ago */
  
$bOk=($t20ago>$_SESSION['last_request'])  /* If the last request was made less than 20 seconds ago */
  
if ($bOk)
    echo 
'okay';
  else
    echo 
'too late';
}
$_SESSION['last_request']=time();  /* Update last request time */ 
Not tested
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-14-09, 10:11 PM
PopSmith PopSmith is offline
Newbie Coder
 
Join Date: May 2009
Posts: 18
Thanks: 5
Thanked 0 Times in 0 Posts
Sorry it took me forever to get back. I am actually in the process of studying and learning PHP so I'm not real good at it yet.

Anyway, I copied and pasted the quoted code in a PHP page created via DreamWeaver before uploading it to my test bed site. I made sure it was a ".php" file and pulled it up in my browser, which gave me the following syntax error:
Quote:
Parse error: syntax error, unexpected T_IF in /home/content/p/o/p/popsmith/html/timertest.php on line 14
I did some googling and messed with the code a bit. However, I didn't have any luck fixing it.

EDIT: "Line 14" is referring to this one:
PHP Code:

if ($bOk
In case it's needed here is the entire code including the edits I did in an attempt to fix the error:
PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Timer test</title>
</head>

<body>
<?php
if (isset($_SESSION['last_request'])) 

  
$t20ago=time()-20;  /* Time 20 seconds ago */ 
  
$bOk=($t20ago>$_SESSION['last_request'])  /* If the last request was made less than 20 seconds ago */ 
  
if ($bOk)
       { 
    echo 
'Bid!';
       }
    else
    {
    echo 
'Finished!'
    }
}
$_SESSION['last_request']=time();  /* Update last request time */
?>
</body>
</html>

Last edited by PopSmith; 05-14-09 at 10:22 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add onclick handlers to all link on a page with one Javascript? sss3d JavaScript 9 02-24-09 12:57 AM
[SOLVED] Multi script PayPal add to cart order form Tito1 JavaScript 5 02-23-09 05:21 AM
Add javascript after load? <?Wille?> JavaScript 14 03-31-06 05:52 AM
add javascript to a php form aburrows182 PHP 3 08-18-05 12:38 PM
How to add an option for multiple quantities using javascript dlogic JavaScript 1 06-29-05 06:29 AM


All times are GMT -5. The time now is 09:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.