PHP重定向相同地址不同端口 [英] PHP Redirect Same Address Different Port

查看:54
本文介绍了PHP重定向相同地址不同端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有这个:

header("Refresh: 0; url=http://192.168.100.100:10500/redirect2.php");

如何进行相同的重定向但不写地址,只写端口?这两个文件位于同一服务器上的同一文件夹中.

How can I do the same redirect but without writing address, only port? Both files are in the same folder on the same server.

问题是我不知道将用于访问此服务器(私人或公共)的地址.

The thing is that I don't know the address that will be used to access this server (private or public).

推荐答案

使用超全局的 $_SERVER 数组、Location 标头和 exit;

Use the superglobal $_SERVER array, Location header and exit;

$port = '10500';
header('Location: '
    . ($_SERVER['HTTPS'] ? 'https' : 'http')
    . '://' . $_SERVER['HTTP_HOST'] . ':' . $port
    . $_SERVER['REQUEST_URI']);
exit;

这篇关于PHP重定向相同地址不同端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆