gpt4 book ai didi

php - 使用 ob_start 时如何在 php 中使用 header 位置重定向?

转载 作者:行者123 更新时间:2023-12-02 17:48:11 24 4
gpt4 key购买 nike

<?php

ob_start();

echo "<body><p>Hello "

if ($condition) {
header( "Location: http://www.google.com/" );
exit;
}

echo " World!</p></body>";
ob_end_flush();

?>

$condition 为真时,我得到:

<body>Hello

我想要的是当 $condition 为真时,然后去谷歌!!!

我不知道发生了什么,你能解释一下或给我一个解决方案吗?

谢谢。

最佳答案

只需在 header 调用之前添加 ob_end_clean();

关于php - 使用 ob_start 时如何在 php 中使用 header 位置重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com