douliu3831 2016-01-30 00:57
浏览 38
已采纳

PHP session_start导致找不到页面

I have a basic "signup" page, and in it, I want to load session variables so part of the form can be repopulated. The problem is, if I call session_start, it causes my page to not be found:

Page Not Found

It doesn't even load enough for me to check for any errors.

I know it's because of session_start since commenting out the call to it causes my page to load.

This is output into my Apache log:

[Fri Jan 29 17:45:21.325743 2016] [mpm_winnt:notice] [pid 5012:tid 544] AH00428: Parent: child process 14060 exited with status 3221225477 -- Restarting.
[Fri Jan 29 17:45:21.964852 2016] [ssl:warn] [pid 5012:tid 544] AH01909: 127.0.0.1:8080:0 server certificate does NOT include an ID which matches the server name
[Fri Jan 29 17:45:22.011733 2016] [mpm_winnt:notice] [pid 5012:tid 544] AH00455: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.1 configured -- resuming normal operations
[Fri Jan 29 17:45:22.011733 2016] [mpm_winnt:notice] [pid 5012:tid 544] AH00456: Apache Lounge VC14 Server built: Dec  9 2015 10:17:39
[Fri Jan 29 17:45:22.011733 2016] [core:notice] [pid 5012:tid 544] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Fri Jan 29 17:45:22.011733 2016] [mpm_winnt:notice] [pid 5012:tid 544] AH00418: Parent: Created child process 12716
[Fri Jan 29 17:45:22.666227 2016] [ssl:warn] [pid 12716:tid 552] AH01909: 127.0.0.1:8080:0 server certificate does NOT include an ID which matches the server name
[Fri Jan 29 17:45:22.828422 2016] [ssl:warn] [pid 12716:tid 552] AH01909: 127.0.0.1:8080:0 server certificate does NOT include an ID which matches the server name
[Fri Jan 29 17:45:22.881476 2016] [mpm_winnt:notice] [pid 12716:tid 552] AH00354: Child: Starting 150 worker threads

And the server doesn't have the request in it's log.

The page code:

<?php
    error_reporting(E_ALL);

    session_start();

    if (isset($_SESSION['mismatch'])) {
        define('MISMATCH_ERROR', true);
    }

    if (isset($_SESSION['missing'])) {
        define('MISSING_ERROR', true);
    }

    if (isset($_SESSION['exists'])) {
        define('EXISTS_ERROR', true);
    }

?>

<!doctype html>
<html>
<head>
    <title>Signup Page</title>
    <style>
        body {
            font-size: 150%;
        }

        label {
            display: inline-block;
            width: 10em;
        }

        form {
            border: 2px groove darkgreen;

            <?php 
                if (defined('MISSING_ERROR')) {
                    echo "background-color: red;";
                }
            ?>
        }

        <?php
            if (defined('MISMATCH_ERROR')) {
                echo "
                    input[type='password'] {
                        background-color: red;
                    }
                ";
            }
        ?>
    </style>
</head>

<body>
    <form method="post" action="handleSignup.php">
        <label for="usernameInput">Username:</label>
        <input type="text" name="username" />

        <br />

        <label for="passwordInput">Password:</label>
        <input type="password" name="password"/>

        <br />

        <label for="passwordReInput">Retype Password:</label>
        <input type="password" name="passwordRe" />

        <br />

        <input type="submit" value="Submit" />

        <?php
            if (defined('EXISTS_ERROR')) {
                echo "Username already exists.";
            }
        ?>


    </form>
</body>

</html>

And I checked phpinfo(), and sessions are enabled.

I'm using XAMPP 3.2.2

  • 写回答

2条回答 默认 最新

  • duanhao9176 2016-01-30 16:54
    关注

    The problem ended up being session.use_cookies in php.ini. It was off by default, despite it recommending it to be enabled, so I toggled it, and it works now.

    Don't forgot to restart the server after making the changes.

    Update:

    For some reason after installing Netbeans, the problem started again. I needed to also enable session.always_use_cookies for it to work again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么