lukeprice Posted July 11, 2006 Share Posted July 11, 2006 Hi,Im totally new to PHP. Im pretty sure this can be done (someone suggested sleep() function but the timer needs to be real time and visible so I think it will have to be a javascript timer) but I don't know what the best way of doing it would be. I can get the JS timer in a form field the integer in that field to do certain things with PHP when you press submit but I want it to be automatic.Countdown goes from 20 --> 0 and on 0 PHP script executes (reloads page or whatever).Any help appreciated.Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/14295-javascript-countdown-timer-reaches-zero-then-some-php-script-auto-executes/ Share on other sites More sharing options...
Daniel0 Posted July 11, 2006 Share Posted July 11, 2006 Now that Web 2.0/AJAX has been so popular, you could use AJAX to do it. Or you could just use the Javascript function 'settimer' (I think it's called that) to set a timer and then go to another page where the PHP script will be run. Quote Link to comment https://forums.phpfreaks.com/topic/14295-javascript-countdown-timer-reaches-zero-then-some-php-script-auto-executes/#findComment-56220 Share on other sites More sharing options...
lukeprice Posted July 11, 2006 Author Share Posted July 11, 2006 I dont know anything about AJAX but if thats the only way of doing I suppose i'll have to learn :), tyAlso, the script needs to update the current page Quote Link to comment https://forums.phpfreaks.com/topic/14295-javascript-countdown-timer-reaches-zero-then-some-php-script-auto-executes/#findComment-56229 Share on other sites More sharing options...
micah1701 Posted July 11, 2006 Share Posted July 11, 2006 I echo Daniel's comments.it doesn't HAVE to be AJAX (which allows you to run server side code after the client side script has loaded) - you can have the count down run and then go to a new page to run the PHP script.but the important thing to remember is that PHP runs Server Side - before the page data is sent to the user's browser - and JavaScript is run Client Side (after the page has finished loading). So it is impossible to run a PHP script after the page has loaded.AJAX is a hack work around, but its not really running the PHP script from the current page, its running a different page, server side, and then forwarding those results to the current browser.[quote]Also, the script needs to update the current page[/quote]then i would just forget AJAX and have a javascript that counts down. when it gets to zero, pass whatever variables you have and reload the page, this time running the PHP script first. Quote Link to comment https://forums.phpfreaks.com/topic/14295-javascript-countdown-timer-reaches-zero-then-some-php-script-auto-executes/#findComment-56232 Share on other sites More sharing options...
lukeprice Posted July 11, 2006 Author Share Posted July 11, 2006 Ok, thankyou. I think I need to do a few more tutorials before I attempt this then. Can anyone suggest any tutorials that are either focused on scripting for online gaming or would be useful in this area in the long run. My idea is to setup a simple text based browser game to learn a bit more about PHP, MySQL and have a bit of fun at the same time.I was thinking of something along the lines of this script, probably makes no sense though... lol:[code]<?php $a = $_REQUEST['d2'] ; while ($a < 0.1) header ("Location: http://localhost/offline/index.html") ; ?>[/code]d2 is a form field containing a JavaScript counter so a can grab the integer from there and check it using the REQUEST and if its below 0.1 I refresh the page, but it only works when you press submit :(. NOTE: An example of the timer setup im looking for can be seen on the MMORPG Syrnia, if anyone has an account there, if you dont its pretty good ;) Quote Link to comment https://forums.phpfreaks.com/topic/14295-javascript-countdown-timer-reaches-zero-then-some-php-script-auto-executes/#findComment-56236 Share on other sites More sharing options...
Daniel0 Posted July 11, 2006 Share Posted July 11, 2006 [quote author=micah1701 link=topic=100196.msg395174#msg395174 date=1152628516]I echo Daniel's comments.it doesn't HAVE to be AJAX[/quote]Never said he had to :P I said he could use a timer instead. Quote Link to comment https://forums.phpfreaks.com/topic/14295-javascript-countdown-timer-reaches-zero-then-some-php-script-auto-executes/#findComment-56238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.