在表单页面上,我有以下内容:
<?php
session_start();
if (isset($_POST['submit'])){
$_SESSION['username'] = $_POST['username'];
}
?>
<form action="index.php">
<input type="text" name="username">
<input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
在文件“index.php”上,我有:
<?php
session_start();
echo ($_SESSION['username']);
?>
Run Code Online (Sandbox Code Playgroud)
但是索引页面上的输出表明会话变量未定义。我该如何解决这个问题,为什么它是未定义的?