小编Jos*_*ell的帖子

PHP:$_SESSION 变量未定义

在表单页面上,我有以下内容:

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

但是索引页面上的输出表明会话变量未定义。我该如何解决这个问题,为什么它是未定义的?

html php session-variables

-1
推荐指数
1
解决办法
1955
查看次数

标签 统计

html ×1

php ×1

session-variables ×1