PHP echo text then sleep 10 seconds then echo another text -


i've tried solutions below links. none of them give luck.

php-output-text-before-sleep

php-output-data-before-and-after-sleep

php-time-delay-using-ob-flush-with-loading-message

actually below script.

<?php include 'ini/ini.class.php'; $compip = $_server['remote_addr']; $inidata = (parse_ini_file("guard.ini",true)); $atm = time()-$inidata["guard"][$compip]; if ($atm>60) { $atm = 1; } echo "<p>you redirected report page in <span id='counter'>" .     $atm . "</span> second(s).</p>";  sleep($atm); //my  //100  //line  //user report mysql $ini = new ini('guard.ini'); $ini->data['guard'][$compip] = time(); $ini->write(); ?> 

still whole content include 'you redirected .......' after $atm (pause seconds) seconds.

my workaround

<?php include 'ini/ini.class.php'; $compip = $_server['remote_addr']; $inidata = (parse_ini_file("guard.ini",true)); $atm = (time()-(isset($inidata["guard"][$compip]) ? $inidata["guard"][$compip] : 0)); if ($atm<60) { echo "<p>you redirected report page in <span id='counter'>" . (60-$atm) . "</span> second(s).</p> <script type='text/javascript'> function countdown() { var j = document.getelementbyid('counter'); j.innerhtml = parseint(j.innerhtml)-1; if (parseint(j.innerhtml)<=0) { j.innerhtml = 0; location.href = 'tr.php'; } } (i=1;i<=" . (60-$atm) . ";i++) { settimeout(function(){ countdown(); },i*1000); } </script>"; } else { mysqlreport; $ini = new ini('guard.ini'); $ini->data['guard'][$compip] = time(); $ini->write(); } ?>  

you can use javascript purpose , pass variables php javascript writing javascript code inside "echo". think trick.

for redirection, below example give idea:

<?php  $url = "http://google.com"; $step = "1000"; $start = 12;  echo 'redirection after <h1 id="counter">'.$start.'</h1> ';  echo '   <script>      var x = '.$start.';      setinterval(function(){       if(x==1){         window.location = "'.$url.'";      }        document.getelementbyid("counter").innerhtml = x;        x--;     }, "'.$step.'");    </script>'; ?> 

as content want output, place tag , javascript. also, can update every 10 seconds; technique this, how you.


Comments