1

I try to run the following tasks

<?php
     echo "<script>alert('yes');</script>";
     flush();
     header('Location: ' . 'index.php');
     exit;
?>

but just one task could work. if I remove flush(), I will not see the alert box. If I use flush() the header can not redirect.

any suggestions or solutions

Mr world wide
  • 4,696
  • 7
  • 43
  • 97
Võ Minh
  • 155
  • 2
  • 12
  • 1
    You cannot send header to another location after echo. – x01saa Jan 15 '17 at 08:48
  • 1
    Possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Cyclonecode Jan 15 '17 at 08:49
  • `header` sends a server-side redirect, alert is JavaScript which is ran client-side. You can't run client-side code before server-side code. You should use JavaScript for the redirect instead. – apokryfos Jan 15 '17 at 08:49

1 Answers1

0

I figure out something work in my purpose, but not the thing I want.

<?php
     echo "<script>alert('yes');</script>";
     ob_flush();
     usleep(1);
   # ob_end_flush();
     echo "abcd";
     echo "abcd";
     echo "abcd";
     echo "abcd";

     usleep(3);
     #ob_start();
     echo '<meta http-equiv="refresh" content="1; url=' . 'http://mintnet.net/' . '" />'; 
    # exit(header("Location: home.php"));
?>   
Võ Minh
  • 155
  • 2
  • 12