如何使用ob_start在PHP中的标题位置重定向? [英] How to redirect with header location in php when using ob_start?

查看:168
本文介绍了如何使用ob_start在PHP中的标题位置重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php 

ob_start();
$ b $ echo< body>< p> Hello

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

echoWorld!< / p>< / body>;
ob_end_flush();

?>

$ condition 为真时, :

 < body> Hello 

我想要的是当 $ condition 将是真的,然后转到Google !!!



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

谢谢。

ob_end_clean(); 。


<?php

ob_start();

echo "<body><p>Hello "

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

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

?>

When $condition is true I get this:

<body>Hello

What I want is when $condition will be true then go to Google!!!

I don't know what is happening, can you explain or give me a solution!?

Thanks.

解决方案

Just add ob_end_clean(); before the header call.

这篇关于如何使用ob_start在PHP中的标题位置重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆