【问题标题】:PHP's session_start causes the page to not be foundPHP session_start 导致页面找不到
【发布时间】:2016-01-30 00:57:12
【问题描述】:

我有一个基本的“注册”页面,我想在其中加载会话变量,以便可以重新填充部分表单。问题是,如果我调用session_start,会导致找不到我的页面:

它甚至不足以让我检查任何错误。

我知道这是因为session_start,因为注释掉对它的调用会导致我的页面加载。

这是输出到我的 Apache 日志中:

[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

并且服务器的日志中没有请求。

页面代码:

<?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>

我检查了phpinfo(),会话已启用。

我正在使用 XAMPP 3.2.2

【问题讨论】:

  • 试试 session_start();回声“你好地球”;在其自己的页面上以排除任何其他编码错误。
  • @Progrock 好主意。确认无法进行精简测试。

标签: php session xampp


【解决方案1】:

你如何存储会话?如果在文件中,请检查会话路径并检查其是否可写。

您还检查了session.gc_* 设置(垃圾收集器)

【讨论】:

  • 我正在使用文件存储。我会检查文件的可写性。
  • 文件路径正确可写。我不确定我在会话 gc 设置中寻找什么。它设置为每 24 分钟一次 gc,但这应该不是问题。如果我可以在这里登录我的笔记本电脑,我会在上面发布我的 gc 设置。
【解决方案2】:

问题最终出现在php.ini 中的session.use_cookies。默认情况下它是关闭的,尽管它建议启用它,所以我切换它,它现在可以工作了。

进行更改后不要忘记重新启动服务器。

更新:

安装 Netbeans 后出于某种原因,问题再次出现。我还需要启用session.always_use_cookies 才能让它再次工作。

【讨论】:

  • 但是应该注意的是,我无法检查会话是否真的有效(我的休息结束了),这个改变只允许页面加载。我会进行测试以确保它在我下一次休息时确实有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多