有没有办法在不使用header()的情况下重定向到php中的另一个页面?我不能使用 header(),因为我首先将一些东西输出到页面。我已经考虑过使用 Javascript 的 window.location,但我在 php 中使用了一个 if 语句,那么在 php 中有什么方法可以在不使用 header() 的情况下转到另一个页面吗?提前谢谢。
我不能使用 header(),因为我首先将一些东西输出到页面。
您不应该使用 header()
关闭。使用输出缓冲仍然可以使用 header()
。
例如:
<?php
ob_start(); //start the buffer
echo "This is some output"; //Output data
ob_clean(); //Erase the buffer content
header('Location: http://google.com'); //Redirect user
使用 PHP?不。
你已经提到使用JS和window.location。
唯一的其他选择是元刷新:
<meta http-equiv="refresh" content="0; url=http://example.com/">
看看 cURL 特别是 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);