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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看