相同的脚本在不同的服务器上不起作用

时间:2012-10-17 12:26:20

标签: php

我正在为进度条编写PHP脚本。

我的代码:

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

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
        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>';
}
?>
<form>
<input type="submit" name="sub" value="Go" />
</form>
</body>

当我在this服务器上测试时,它运行正常。但是在this服务器上它显示“进程已完成”。点击Go按钮后..

我在两台服务器上使用相同的编码...

我的错误是什么?任何的想法? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

PHP 5.3.0中服务器上的php.ini可能会从$_REQUEST中排除cookie,因此服务器上的php.ini可能需要相应编辑。

如果您无法编辑php.ini,请使用$_POST / $_GET等代替$_REQUEST

如果您不知道变量的发送方式,请使用以下内容:

switch($_SERVER['REQUEST_METHOD']) {
    case 'GET': $the_request = &$_GET; break;
    case 'POST': $the_request = &$_POST; break;
    default:
}

由于php.ini设置,它可能也是flush()函数不起作用。请参阅php.net flush() reference下的用户评论 - 有关如何编辑php.ini以使其正常工作的一些建议列在那里。