0

可能重复:
PHP 如何将标题位置定位到父目录中的页面?

函数 header() 找不到上面的目录。

$link = "../hide/success-registr.phtml";
header("Location: $link");

它的路径正确且文件存在。

4

3 回答 3

1

您需要提供一个绝对 URL,例如:

$link = "http://www.mydomain.tld/public/success-registr.phtml";
header("Location: $link");

注意:浏览器将请求提供的 URL,因此无法使用“隐藏”页面/响应。

于 2013-01-25T14:52:04.637 回答
0

来自 php.net

HTTP/1.1 需要绝对 URI 作为 » Location 的参数:包括方案、主机名和绝对路径,但有些客户端接受相对 URI。

始终建议使用带有 header() 位置的绝对路径(完整 uri)。

有时相对路径会起作用,但肯定不会在目录结构中上升一个级别,除非您在将路径作为参数传递之前对路径进行一些操作。

于 2013-01-25T14:57:06.950 回答
-3

你可以试试

$link = realpath('../hide/success-registr.phtml');
$rootPath = 'some/root/path';

$link = str_replace($rootPath, 'http://', $link);
于 2013-01-25T14:52:18.403 回答