简体   繁体   English

PHP从包含文件重定向

[英]php redirect from include file

When I add the php redirect command in an include file, it redirects just that area, in its little sub window. 当我在包含文件中添加php redirect命令时,它将仅在其小子窗口中重定向该区域。

How can I make a redirect work with the base page? 如何使重定向与基本页面一起使用?

Is it even possible, because you can only redirect before the headers, can't you? 甚至有可能,因为您只能在标题之前重定向,对吗? Would I have to use javascript instead? 我必须改用javascript吗?

If you are not talking about iframes 如果您不是在谈论iframe

You can use output buffering to get round this issue. 您可以使用输出缓冲来解决此问题。 At the beginning of your main script run: 在主脚本的开头运行:

ob_start();

And then once you are done at the bottom of your main script run: 然后,一旦完成主脚本的底部,请运行:

ob_end_flush();

From the manual page linked above: 从上面链接的手册页:

This function will turn output buffering on. 此功能将打开输出缓冲。 While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. 当输出缓冲处于活动状态时,脚本(头文件除外)不发送任何输出,而是将输出存储在内部缓冲区中。

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). 可以使用ob_get_contents()将内部缓冲区的内容复制到字符串变量中。 To output what is stored in the internal buffer, use ob_end_flush(). 要输出存储在内部缓冲区中的内容,请使用ob_end_flush()。 Alternatively, ob_end_clean() will silently discard the buffer contents. 或者,ob_end_clean()将静默丢弃缓冲区内容。

If you want to redirect parent window from <iframe (I assume that's what you mean by "little sub window") you have to use javascript, probably: self.parent.location.href = '...'; 如果要从<iframe重定向父窗口(我假设这就是“小子窗口”的意思),则必须使用javascript,可能是: self.parent.location.href = '...';

Google for javascript parent redirect to get more examples. Google for javascript父重定向可获取更多示例。

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

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