duandaotuo5542 2016-08-05 03:53
浏览 28

标头重定向后无法维护会话值

  <?php 

        $mysql_handle = mysql_connect($dbhost, $dbuser, $dbpass)
            or die("Error connecting to database server");
        mysql_select_db($dbname, $mysql_handle)
            or die("Error selecting database: $dbname");
    ?>

    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    </head>

    <body>
        <center>
        <h2>Sorry, it looks like you lost...</h2>
        <h3>Your score was: <?php echo $_SESSION["score"] ?>! If this was your highest score, it has been saved.</h3>
        <button id="restartButton" type="button" onclick="restart()" name="restart" class="btn btn-info">Restart</button>
        </center>
    </body> 
    </html>
    <script>
        //when restart is clicked 
        function restart()
        {
            header("http://web.engr.oregonstate.edu/~chathamb/CodingPractice/ImprovedPongGame/game.php");
        }

    </script>
    <?php 


        mysql_close($mysql_handle);
    ?>

This is my code in gameOver.php and I can't seem to figure out why my $_SESSION["score"] is not being maintained properly. My first time through testing, it displayed 4 correctly, now I'm having some issues even printing out the echo and it will not reset after the restart() function that executes the header redirect.

From my research, I think the issue revolves around the header() redirect, but I can't seem to figure it out. I tried an AJAX workaround but it didn't work.

And yes, session_start(); is at the very top of my code on my game.php code. The game.php code is pretty long and kind of messy so I will save you all from the pain of seeing that.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题