You can give progress messages like echo "15% done"
from within your cycle in redirect.php
.
Suppose currently your code is:
<?php
$N = 100000; // this is how many iterations you will make in your work
for ($i = 0; $i < $N; $i++) // This is the loop that does the work in your script
{
do some part of your work...
}
?>
For the messages to be shown, you will need to do this in PHP:
<?php
ob_start ();
$percent_previous = 0;
$N = 100000; // this is how many iterations you will make in your work
for ($i = 0; $i < $N; $i++) // This is the loop that does the work in your script
{
do some part of your work...
$percent = $N / ($i + 1) * 100;
if ($percent_previous != $percent) // not to show it too frequently
{
message ("$percent% done...");
$percent_previous = $percent;
}
}
// after the work done:
if ($percent_previous != 100)
progress (100);
function message ($msg)
{
echo "<!-- some 4 KB of random garbage like jhajdhsjahsjaheuwbcwuvacjacv -->";
echo $msg;
ob_end_flush ();
ob_flush ();
flush ();
ob_start ();
echo "<!-- some 1 KB of random garbage like hdsjfagdfqhwjcwwvyvcsdhalj -->";
}
?>
I echo
before and after the messages a long comment with garbage <!-- hdjhsjsjdshjd ->
(some 4 kilobytes) to reset the network's and browser's caching mechanisms. I use garbage because if I just use some 4 KB of spaces, it can be compressed and the resulting transmitted message will not be large enough.
You can start from <span class=someclass>
and after 100% close this tag; then execute a JavScript to erase the progress messages.
Of course the same can be done with images, and you can nicely format your progress messages.
If you only want a gif to show and disappear after the calculation finishes, then you can proceed along these lines:
<html>
<body>
<?php
ob_start ();
progress ("<span id='progress'><img src='progress.gif'></span>");
// You still need the trick I described above for this to be shown in real time
// do all your long work here
?>
<script>
document.getElementById ("progress").innerHTML = ''; // This erases the image
</script>
</body>
</html>
A complete example using the OP's sample code is:
<html>
<body>
<?php
ob_start ();
message ("<span id='progress'><img src='progress.gif'></span>");
// You still need the trick I described above for this to be shown in real time
$name = $_POST['name']; // OP's code
$age = $_POST['pass']; // OP's code
if($name==!NULL || $age==!NULL) // OP's code
echo "Successfully returned"; // OP's code
echo $name; // OP's code
else // OP's code
echo "Returned Failed"; // OP's code
function message ($msg)
{
echo "<!-- some 4 KB of random garbage like jhajdhsjahsjaheuwbcwuvacjacv -->"; // please include here at least some 4 kilobytes of such random garbage, I will not type it here
echo $msg;
ob_end_flush ();
ob_flush ();
flush ();
ob_start ();
echo "<!-- some 1 KB of random garbage like hdsjfagdfqhwjcwwvyvcsdhalj -->"; // please include here at least some 1 kilobyte of such random garbage, I will not type it here
}
?>
<script>
document.getElementById ("progress").innerHTML = ''; // This erases the image
</script>
</body>
</html>
ajax form submit preloader