如何在PHP中重定向到同一页面

编程入门 行业动态 更新时间:2024-10-10 12:22:59
本文介绍了如何在PHP中重定向到同一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用PHP重定向到同一页面?

How can I redirect to the same page using PHP?

例如,本地我的网址是:

For example, locally my web address is:

localhost/myweb/index.php

如何在我的网站内重定向到另一个页面,例如:

How can I redirect within my website to another page, say:

header("Location: clients.php");

我知道这可能是错误的,但是我真的需要把整个内容放进去吗?如果以后不是localhost/怎么办?

I know this might be wrong, but do I really need to put the whole thing? What if later it is not 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 (文档)属性,这些属性返回有关当前页面的信息,但是我的首选方法是使用$_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: " . "" . $_SERVER['HTTP_HOST'] . $location);

其中$location是域之后的路径,以/开头.

where $location is the path after the domain, starting with /.

更多推荐

如何在PHP中重定向到同一页面

本文发布于:2023-10-10 18:39:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479402.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   页面   如何在   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!