PHP脚本永远加载

时间:2016-08-24 13:25:50

标签: php loops cookies infinite

这不是Maximum execution time in phpMyadmin的副本;这与phpmyadmin无关。

在我的网站上,有一个表单将POST数据发送到PHP脚本并加载新页面。提交表单时,页面将永远加载,然后生成:

  

XXX.XXX页面无效XXX.XXX目前无法处理   这个请求。 HTTP ERROR 500

我认为这可能是一个流量问题,所以我升级了我的主机SSD并让网站只供我测试,但问题仍然存在。这是我的剧本:

EOFException

可能导致此问题的原因是什么?

编辑:错误日志显示:

<?php

$used_file  = 'used.txt';
$codes_file = 'codes.txt';

# Generates a random unused code from the code file 
function genCode() {
    global $used_file, $codes_file;
    $codes = file_get_contents($codes_file);
    $codes = explode("\n", $codes);
    $used  = file_get_contents($used_file);
    $used  = explode("\n", $used);
    foreach($codes as $code) {
        if(!in_array($code, $used))
            return $code;
    }
}

# Generate error string from error code
function getError($err) {
    switch($err) {
        case 1: return 'No submit';
        case 2: return 'Wrong password';
        case 3: return 'No password';
    }
}

# Adds generated code to the 'used' codes file
function append_used($code) {
    global $used_file, $codes_file;
    $str = $code . '\n';
    file_put_contents($used_file, $str, FILE_APPEND);
}

# Get user's IP (for cookie handling)
function getIP() {
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}

# Cookie handling
# Set a cookie for how many times the form has been submitted by user

$used = 0;

if(isset($_COOKIE['used_twice'])) {
    $used = 3;
}

if(isset($_COOKIE['used_once']) && !isset($_COOKIE['used_twice'])) {
    setcookie('used_twice', getIP(), time()+18000);
    $used = 2;
}

if(!isset($_COOKIE['used_once'])) {
    setcookie('used_once', getIP());
    $used = 1;
}

# Check if all the POST data is correct

$password = $_POST['inputPassword'];
$submit   = $_POST['submit'];

if(isset($password)) {

    if($password == 'test123') {

        if(isset($submit)) {

            $code = genCode();

        }

        else
            $err = 1;

    } else 
          $err = 2;

} else
    $err = 3;



# Now generate the new page
include 'web_functions.php';
getHead('Generated', 'Generated code');
getBody('Generated code');

?>



            <a href="../"><img src="goback.png"></img></a>
            <h2>Code Generated</h2>
            <br/>

            <?php
            if(!isset($err) && isset($thecode) && $used == 1) {
            ?>
            <center>
                <div class="bs-component">
                <div class="alert alert-dismissible alert-success">
                <p>Your code is: </p> <strong> <?php echo $thecode; append_used($thecode); ?> </strong>
                </div>
                </div>
            </div>
            </center>
            <?php
            } elseif(isset($err)) {
            ?>
            <center>
            <div class="bs-component">
            <div class="alert alert-dismissible alert-danger">
            <p>There was an error:</p> <strong><?php echo getError($err); ?></strong>
            </div>
            </div>
            </div>
            </center>
            <?php
                } elseif(!isset($err) && $used != 1){
                ?>
                <center>
                <div class="bs-component">
                <div class="alert alert-dismissable alert-danger">
                <p>You can only use the code generator once every 5 hours. Please try again later.</p>
                </div>
                </div>
                </div>
                </center>
                <?php } else { ?>
                <div class="bs-component">
                <div class="alert alert-dismissable alert-danger">
                <p>There was an unexpected error. Please try again.</p>
                </div>
                </div>
                </div>
                <?php } ?>

                <br/>
                <br/>
                <br/>


                <?php closeTags();
                getFooter(); ?>
      </div>


 </div>


 </div>
</div>

第13行在foreach循环中。

0 个答案:

没有答案