943,154 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1375
  • PHP RSS
Feb 2nd, 2010
0

[HELP] Time Limit

Expand Post »
How can I set a time limit for a user to stay on a web page. Let me explain it to you;

Let suppose I've two web pages, page-A and page-B. When the user is on page-A, he needs to stay at this page for 30 secs before going to page-B. If the user directly visit the page-b, then the error is shown to the user with the remaining sec left to visit page-B. When the timer reaches to 0 sec or you can say 30 secs are over, then the user can view the content of page-b..

Can anyone let me know how can I do it?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mujahid158 is offline Offline
23 posts
since Oct 2007
Feb 2nd, 2010
0
Re: [HELP] Time Limit
With the help of Ajax you can achieve this.
Call a timer function onload inside body tag.After its execution do your task.May be you can show the link to pageB only at that time.
Reputation Points: 12
Solved Threads: 24
Junior Poster
Manuz is offline Offline
122 posts
since Oct 2008
Feb 2nd, 2010
0
Re: [HELP] Time Limit
Ajax can do it. Plain js can do it. OR php can do it via header refresh. The plain js window.location using time intervals is the usual method, but if js is not enabled, I don't think that the page will be redirected.

PHP Syntax (Toggle Plain Text)
  1. header( 'refresh: 30; url=http://www.example.com/index.php' );
  2. ...(rest of page)....

After 30 seconds, the page is redirected or refreshed (if sent to itself).
Sponsor
Featured Poster
Reputation Points: 1041
Solved Threads: 935
Sarcastic Poster
ardav is offline Offline
6,620 posts
since Oct 2006
Mar 8th, 2010
0
Re: [HELP] Time Limit
Alright, i make it easy for you guys. You can take the example of a rapidshare where we've to wait few seconds before downloading the file.. My case is kinda different as I want the user to wait for the specific time before going to page b. If the user visits page b before the counter ends, the error is shown to the user. When the counter ends, the user is allowed to view the content of page b...

Also, I would be grateful if anyone can provide me the code.. I've searched on Google too much but can't find a way... It's urgent

EDIT: BTW, you can also take the example of neobux.com .. If you closed the ad before 30 seconds and try to visit a new ad, the error is shown to you with the remaining time you've to wait...
Last edited by Mujahid158; Mar 8th, 2010 at 10:05 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mujahid158 is offline Offline
23 posts
since Oct 2007
Mar 8th, 2010
0
Re: [HELP] Time Limit
To show a countdown, you'll need js. To provide a 'sorry you're too early', an easy solution would be to set a session variable (or cookie).

first page
php Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. if(isset($_SESSION['allowed_view'])){
  4. $delay = $_SESSION['allowed_view'] - time(); //for redirects back to this page
  5. $error_msg = "<p>You cannot proceed until the countdown is finished.</p>";
  6. }else{
  7. $delay = '30'; //countdown time in seconds for first time page entry
  8. $error_msg = "";
  9. $_SESSION['allowed_view'] = time() + $delay; //set time at which page can be redirected
  10. }
  11. //place your timer (either js for coundown display - place in head area OR php with refresh method, if countdown not impt - USING $delay as timer).
  12. ?>

second page
php Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. $current = time();
  4. if(!isset($_SESSION['allowed_view']) || $current < $_SESSION['allowed_view']){
  5. //redirect back to sending page
  6. }else{
  7. unset($_SESSION['allowed_view']); //safely remove this variable - or do something more exotic.
  8. }
  9. ?>

Top of head stuff, so don't know if it'll work without a fiddle. Haven't included a coundown script - that you can do yourself - loads of free scripts available.
Last edited by ardav; Mar 8th, 2010 at 12:58 pm.
Sponsor
Featured Poster
Reputation Points: 1041
Solved Threads: 935
Sarcastic Poster
ardav is offline Offline
6,620 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Problem in Updating passwords in PHP-MySQL
Next Thread in PHP Forum Timeline: string to upper input forum





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC