1

I been searching around for a simple code but yet I don't found one that is working for me. I tried using setInterval but turn out the code didn't do well.

<?php switch(n){ case 1: //do this; //then go to next page after this seconds; } ?>

I tried to put javascript into the switch..case,

echo "<script type='text/javascript'>setInterval(location.href = 'goHere.php', 3000);
</script>"

it direct me into the next page without counting down. Any solutions?

  • Use `setTimeout` to perform any action after certain timeout... – Rayon Feb 22 '16 at 04:10
  • This page might have some useful bits for the countdown timer http://stackoverflow.com/questions/34241575/php-session-variable-not-parsing-but-isset-says-it-is-running-at-0/34248806#34248806 – Steve Feb 22 '16 at 04:16
  • @RayonDabre I tried using setTimeout it still redirect me without counting the time. Maybe I did it wrong. Thanks anyway :D. – David Dasie Feb 22 '16 at 04:20

1 Answers1

1

you can use header function of php

header( "refresh:5;url=wherever.php" );

and if you wants to use javascript then you can use setTimeout

setTimeout(function () {
   window.location.href= 'http://www.google.com'; // the redirect goes here

},5000);
shubham715
  • 3,324
  • 1
  • 17
  • 27