php 如何刷新当前页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32420145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:57:59  来源:igfitidea点击:

How to refresh the current page

phpdrupal

提问by Gus

I'm customizing a module in Drupal and in that module I'd like to refresh the current page right after an if statement, how can I refresh the current page in PHP

我正在 Drupal 中自定义一个模块,在该模块中我想在 if 语句之后立即刷新当前页面,如何在 PHP 中刷新当前页面

回答by q.Then

You can't in PHP if you've already outputted something (since all headersmust be sent before output begins).

如果您已经输出了一些东西,则不能在 PHP 中使用(因为所有内容都headers必须在输出开始之前发送)。

If you haven't outputted:

如果你还没有输出:

header('Location:: current_page_url');
or
header("Refresh:0");

Better way is to do it through Javascript with the windowobject

更好的方法是通过 Javascript 与window对象

$window.location.reload();

回答by Andrew Mata

Php offers the following function to invoke a page refresh

PHP 提供了以下函数来调用页面刷新

header("Refresh:0");

If you require a page redirect you can use the following.

如果您需要页面重定向,您可以使用以下内容。

header("Refresh:0; url=redirect_page.php");

回答by Drop Shadow

just header("Refresh:0");

只是标题(“刷新:0”);