How to redirect to the same page in PHP(如何在 PHP 中重定向到同一页面)
问题描述
如何使用 PHP 重定向到同一页面?
How can I redirect to the same page using PHP?
比如我本地的网址是:
http://localhost/myweb/index.php
如何在我的网站内重定向到另一个页面,例如:
How can I redirect within my website to another page, say:
header("Location: clients.php");
我知道这可能是错误的,但我真的需要把整个事情都写出来吗?如果稍后它不是 http://localhost/ 怎么办?
I know this might be wrong, but do I really need to put the whole thing? What if later it is not http://localhost/?
有没有办法做这样的事情?另外,我有很多代码,然后在处理完一些代码后最后......我正在尝试使用它进行重定向.可以吗?
Is there a way to do something like this? Also, I have a lot of code and then at the end after it is done processing some code... I am attempting to redirect using that. Is that OK?
推荐答案
有许多不同的$_SERVER (docs) 返回有关当前页面的信息的属性,但我的首选方法是使用 $_SERVER['HTTP_HOST']:
There are a number of different $_SERVER (docs) properties that return information about the current page, but my preferred method is to use $_SERVER['HTTP_HOST']:
header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . $location);
其中 $location 是域之后的路径,以 / 开头.
where $location is the path after the domain, starting with /.
这篇关于如何在 PHP 中重定向到同一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PHP 中重定向到同一页面
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
