我有一个 PHP 代码可以重定向到其他域,这个
<?php
header("Location: {$_GET['url']}");
echo 'You are redirecting to ... page';
sleep(5);
?>
它的工作原理就像当我在 http://my-domain.com/URL.php?url= 末尾添加任何外部 url 时,它只会重定向到外部域,在这种情况下,让我们使用谷歌:
它只是在加载 5 秒后直接重定向到页面上,但我想显示一个带有一些装饰(如加载图标)和一些文本(如
"Please wait while you're being redirected to http://www.google.com"
)的 php 页面我也试过
echo 'Please wait while you're being redirected';
但它只是直接重定向到外部域而不显示消息。 最佳答案
如果你不想让 javascript 做超时,你可以在 php 头函数中添加刷新定时器:
header("Refresh: 5; url={$_GET['url']}");
或者去 super 老派并在 html 中吐出这个:
echo '<meta http-equiv="refresh" content="5; url='. $_GET['url'] .'">';
编辑:我想提一下,如果你是老派,一定要清理 url(不要像上面的例子那样盲目地传递 GET 变量)。
关于php - 如何在php页面中添加文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46745591/