欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

how to redirect to the same page in php 重定向到 本机 本服务器 某个网址

shiping1 的头像

how to redirect to the same page in php

如何重定向到PHP中的同一页



How can i redirect to the same page using PHP. For example in local my web address is

http://localhost/myweb/index.php

How can I redirect within my website to another page say

header("Location: clients.php");

I know this might be wrong, but do I really need to put the whole thing?, what if later it is nothttp://localhost/ ?

Is there any 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?

我怎样才能重定向到使用PHP同一页面。例如,在当地我的网络地址是
HTTP //localhost/myweb/index.php

如何将我的网站中的重定向到另一页说

标题“位置:clients.php” );

我知道这可能是错的,但我真的需要把整个事情?如果以后有什么不可以的http://本地主机/

有没有办法做这样的事情?另外,我有很多的代码,然后在它到底是做了一些处理代码后..我尝试使用重定向,可以吗?


 

正确答案 
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);

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


许多不同的$ _ SERVER文档)返回有关当前页面的信息的属性,但我的首选方法是使用$ _ SERVER ['HTTP_HOST']

标题“位置:”   “HTTP://”  $ _ SERVER [ 'HTTP_HOST' ]  $位置);

其中,$位置是域之后的路径,从/

 
 
   
I i am not sure why it is not redirecting, maybe i did it wrong? $location= '/index.php'; header("Location: " . "http://" . $_SERVER['HTTP_HOST'] .$location); – user710502 Nov 15 '11 at 3:21
1 
For debugging, simply output that string with echo instead of header. If it is correct, then something else is wrong (headers must be the first output on the page, for example.) – NickC Nov 15 '11 at 3:24
   
Too short to edit, but the line should have ) at the end of it. – Goose Dec 31 '15 at 16:53
   

普通分类: