简体   繁体   English

使用PHP标头重定向到同一页面不会从URL中删除GET请求

[英]Redirecting to the same page with PHP headers is not removing the GET request from the URL

I have a hangman game. 我有一个子手游戏。 My problem is that when they get to the win screen, they can refresh it infinitely and each refresh will increment their amount of wins (or losses if they lost), as it checks if the word is complete, it is, and ups their points. 我的问题是,当他们进入获胜画面时,可以无限刷新它,每次刷新都会增加获胜的次数(如果输了,则会增加损失),因为它会检查单词是否完整,正确并提高积分。

I now made a SESSION variable to tell whether or not they have won. 我现在做了一个SESSION变量来告诉他们是否赢了。 If they have, it resets the game. 如果有,它将重置游戏。

My problem is that when they refresh with the GET request in the URL (how do I guesses) such as ...index.php?guess=G the game will refresh with G being guessed. 我的问题是,当它们使用URL中的GET请求刷新时(我怎么猜),例如...index.php?guess=G ,游戏会刷新并猜测到G。 I thought a header with Location set to index.php would get rid of the GET request. 我认为将Location设置为index.php的标头将摆脱GET请求。

Here's my detecting code: 这是我的检测代码:

    if (isset($_SESSION["won"]) && $_SESSION["won"]) {
        reset_game();
    }
    else if (isset($_SESSION["lost"]) && $_SESSION["lost"]) {
        reset_game();
    }

And the reset_game() function: reset_game()函数:

    function reset_game() {
        $_SESSION["word"] = generate_word("dictionary.txt");
        $_SESSION["word-progress"] = turn_to_underscores($_SESSION["word"]);
        $_SESSION["chances-left"] = 9;
        $_SESSION["guesses"] = array();
        $_SESSION["incorrect-guesses"] = array();

        header('Location: index.php');
    }

Why isn't this working? 为什么这不起作用?

I believe header("Location: index.php"); 我相信header(“ Location:index.php”); will remove all the get parameters from the URL. 将从网址中删除所有get参数。

I think you need to check whether your application did call the function 我认为您需要检查您的应用程序是否确实调用了该函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM