1
我正在丢失会话变量,同时使用以下代码维护会话ID。丢失会话变量,同时保持会话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'];
?>
输出显示会话标识,但没有显示用户名会话变量。
值得注意的是我的全部代码工作,直到我通过我的服务器公司购买SSL并添加重定向代码与这些文件的文件夹的htaccess文件。使用的代码是:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domainname.com/foldername/$1 [R,L]
这个成功重定向的用户使用http转到使用http到https的相同位置的位置。我也尝试添加RewriteCond %{HTTPS} off
以确保在用户最初使用https时不会发生重定向,但这不起作用。
有没有解决方案,我的会话变量持续?