【问题标题】:Losing session variables while maintaining session id在维护会话 ID 的同时丢失会话变量
【发布时间】:2017-12-03 15:07:57
【问题描述】:

在使用以下代码维护会话 ID 时,我丢失了会话变量。

index_simplified.html

<!DOCTYPE HTML>
<html>
    <body>
        <form action="processLogin_simplified.php" method="post">
            username:
            <input type="text" class="textfield" name="username">
            <input type="submit" name="login" value="Login">
        </form>
    </body>
</html>

processLogin_simplified.php

<?php
    session_start();

    $_SESSION['username'] = $_POST['username'];
    session_write_close(); // tried with and without this line

    header('Refresh: 0; URL=https://www.domainname.com/foldername/dashboard_simplified.php');
    exit(); // tried with and without this line
?>

dashboard_simplified.php

<?php
    session_start();
    echo 'session id:' . session_id();  
    echo '<br><br>username: ' . $_SESSION['username'];
?>

输出显示会话 ID,但没有显示用户名会话变量。

值得注意的是,在我通过服务器公司购买 SSL 并将重定向代码添加到包含这些文件的文件夹的 htaccess 文件之前,我的完整代码一直有效。使用的代码是:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.domainname.com/foldername/$1 [R,L]

这成功地将使用 http 访问该位置的用户重定向到使用 https 的同一位置。我还尝试添加 RewriteCond %{HTTPS} off 以确保在用户最初使用 https 时不会发生重定向,但这没有效果。

是否有解决方案使我的会话变量持续存在?

【问题讨论】:

    标签: php .htaccess session redirect session-variables


    【解决方案1】:

    这已由我的托管公司解决。显然,“会话 .save_pth 未在 php.ini 文件中正确设置”。不完全确定这意味着什么,但很高兴它现在正在工作。希望对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 2011-12-05
      • 2011-03-09
      • 2012-10-18
      • 2011-05-20
      相关资源
      最近更新 更多