drt12345678 2013-12-16 19:01
浏览 86
已采纳

使用header()重定向。 标头()不起作用(可能是因为数据已发送)

I am working on a noughts and crosses project. I am trying to redirect the user to a "Please wait" page while the other user has their move.

At the start of the game I give each player a letter (I know this works).

$find_user = mysql_query("SELECT `user_id` FROM `games` WHERE `game_id`='".$number_of_games."'");
$find_user = mysql_result($find_user, 0);

if($find_user == $_SESSION["userId"]) {
    $letter = "X";
} else {
    $letter = "O";
}

The rest of the page is generated and stuff is written to the page.

After the user takes their move the following is run:

header("Location: ../wait".$turn.".php");

This works for the person who is "X" (The person who creates the game on the database) and they are redirected to a page saying "Please wait for O to have their move.".

However when "O" has their move, they are not redirected to wait now page.

The header is in the same place in the code.

Also, if this makes any difference... The following code is at the bottom of the php file that the player plays the game on (To refresh it).

$url=$_SERVER['REQUEST_URI'];
header("Refresh: 5; URL=$url"); 

I know the structure is messed up, but its my first big PHP project and I could do with some help.

Why is redirecting for "X" but not for "O"?

Update:

If I type:

print("<script>top.location.href = '../waitO.php'</script>");

It redirects.

If I type:

print("<script>top.location.href = '../wait'".$letter."'.php'</script>"); 

It does nothing.

  • 写回答

2条回答 默认 最新

  • doucaigai7176 2013-12-16 19:09
    关注

    you can also redirect like this:

    print("<script>top.location.href = '...'</script>")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集