从 LAN 计算机上的一个 php 文件重定向到另一个文件

Redirection to another file from one php file from computer on LAN

我在计算机A上创建了一个本地服务器。 让服务器 ip 地址在 LAN 上为 192.168.1.1。

现在我正尝试从局域网中的另一台计算机 B 访问 file1.php:

192.168.1.1/file1.php

在 file1.php 中,我使用 :

重定向到另一个名为 file2.php 的文件

header("位置:./file2.php");

所以应该重定向到 192.168.1.1/file2.php。但它正在重定向到 localhost/file2.php.

如何操作。

您可以像这样使用完整地址重定向:

header('Location: http://192.168.1.1/file1.php');

如果你做了,有没有错误?

怎么样:

header('Location: http://'.$_SERVER['SERVER_ADDR'].'/file1.php');

SERVER_ADDR returns您所在网页的IP地址。

https://www.php.net/manual/en/reserved.variables.server.php