Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Redirecting In.. CountDown Timer PHP

I have this code so far that redirects the user after 5 seconds to the correct URL:

<?php $url = $_GET['url']; header("refresh:5;url=$url"); include('ads.php'); ?>

Please could you tell me how i could display a countdown timer saying Redirecting In.. with .. being the amount of seconds left. I am new to web development so all code will be helpful!

like image 613
max_ Avatar asked Nov 29 '22 18:11

max_


1 Answers

<script type="text/javascript">

(function () {
    var timeLeft = 5,
        cinterval;

    var timeDec = function (){
        timeLeft--;
        document.getElementById('countdown').innerHTML = timeLeft;
        if(timeLeft === 0){
            clearInterval(cinterval);
        }
    };

    cinterval = setInterval(timeDec, 1000);
})();

</script>

Redirecting in <span id="countdown">5</span>.

You can try this.

like image 115
Kyle Avatar answered Dec 05 '22 07:12

Kyle