Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing PHP script for Progress bar.

My code:
HTML
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>

PHP
<?php
ob_start();
if(isset($_REQUEST['sub']))
{
// Total processes
    $total = 10;

    // Loop through process
    for($i=1; $i<=$total; $i++){
        // Calculate the percentation
        $percent = intval($i/$total * 100)."%";

        // Javascript for updating the progress bar and information
        echo '<script language="javascript">
        document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
        document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
        </script>';

        // This is for the buffer achieve the minimum size in order to flush data
        echo str_repeat(' ',1024*64);

        // Send output to browser immediately
        ob_flush();
        flush();

        // Sleep one second so we can see the delay

        sleep(1);
    }

// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>

HTML
<form>
<input type="submit" name="sub" value="Go" />
</form>
</body>



when I test it on this server it runs properly. But on this server it show me "Process completed". after clicking Go button..

I have refer this Article But it does not work for me..
Please help me. it is pain for me.
I Used same coding on both server...

what is my mistake ? Any idea?
Thanks in advance.
Posted

1 solution

The php.ini on the server as of in PHP 5.3.0 may exclude cookies from $_REQUEST, so it might be the php.ini on the server that needs to be edited correspondently.

If You don't have ability to edit php.ini, use $_POST / $_GET etc instead of $_REQUEST.

If You don't know which way Your variable is sent, use something like this:

switch($_SERVER['REQUEST_METHOD']) {
case 'GET': $the_request = &$_GET; break;
case 'POST': $the_request = &$_POST; break;
default:
}
It might also be the flush() function that does not work due to php.ini settings. See user comments under php.net flush() reference - some recommendations about how to edit php.ini to make it work are listed there.
 
Share this answer
 
Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900