标题重定向后,PHP会话索引是否未定义?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了标题重定向后,PHP会话索引是否未定义?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经挣扎了好几个小时,但我无法让它发挥作用.当我重定向到另一个 PHP页面时,我的所有会话变量都为null.我在xampp服务器上. @H_301_1@session.PHP文件

<?PHP
     session_start();
     if(isset($_POST['submITted']))                                                                                         
     {   
        $_SESSION['First_name'] = "MAX";
        var_dump($_SESSION);
        header("Location: http://localhost:8080/secure login/session2.PHP");     
        die();
     }
?>
<!DOCTYPE htML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html XMlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> <Meta http-equiv="Content-type" content="text/html; charset=ISO-8859-    1" /> 
    <title>You LOGged In</title> 
</head> 
<body> 
    <form action="session.PHP" method="post">
        <div align="center"><input type="submit" name="submit" value="Login" /></div>
    <input type="hidden" name="submitted" value="TRUE" />
    </form>
</body>
</html>
@H_301_1@session2.PHP

<?PHP
    session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> <Meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    <title>You Logged In</title> 
</head> 
<body> 
    <div id="main"> 
        <?PHP 
            echo '<PRe>' . print_r($_SESSION,TRUE) . '</pre>';
            echo 'You are welcome to session2.PHP <br></br>'; 
            if (isset($_SESSION['first_name'])) 
            { 
                echo $_SESSION['first_name'] . "<br></br>";
            }
            else
            {
                echo "Your session doesn't exist. I hate PHP <br></br>";
                echo $_SESSION['first_name'];
            }
        ?>
    </div>
 </body>
 </html>
@H_301_1@会话不保存,输出为;

Array
(
)
You are welcome to session2.PHP
Your session doesn't exist. I hate PHP
Notice: Undefined index: first_name in C:\xampp\htdocs\secure login\session2.PHP on line 28
@H_301_1@我尝试过其他一些事情,例如将会话变量从xampp / tmp保存到另一个目录,但这并没有解决问题.我有一个程序,当我进行重定向时,我需要让用户登录,但这已经阻止了我超过一天.

@H_301_1@更新:

@H_301_1@目录之间的空间不是问题,它暂时解决了问题,但那是因为新目录还没有缓存.无论如何,再过几天,我调试并意识到我在我的localhost上运行了两个程序.两者都在使用会话,因此如果终止会话,它也会终止另一个会话,因为localhost就像一个域名,并且只存在一个会话.特别是,我的其他程序的logout.PHP并没有破坏会话,而是因为你必须删除浏览器缓存而不是它的混乱.我正在清空会话数组,破坏会话,并销毁cookie,这是问题所以我无法再次登录.我所要做的就是只破坏会话;

@H_301_1@见 – > Killing off Global Session Variable as a logout button

好像你有问题,因为你有一个名称安全登录的空间
localhost:8080/secure%20login/session.PHP
@H_301_1@因此,请尝试使用下划线secure_login更改名称,并更改您的代码

<?PHP
     session_start();
     if(isset($_POST['submitted']))                                                                                         
     {   
        $_SESSION['first_name'] = "MAX";
        VAR_dump($_SESSION);
        header("Location: http://localhost:8080/secure_login/session2.PHP");     
        die();
     }
?>

脚本宝典总结

以上是脚本宝典为你收集整理的标题重定向后,PHP会话索引是否未定义?全部内容,希望文章能够帮你解决标题重定向后,PHP会话索引是否未定义?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。