Php 单击';提交';,我想被重定向回同一页,使用相对路径

Php 单击';提交';,我想被重定向回同一页,使用相对路径,php,html,xml,redirect,http-headers,Php,Html,Xml,Redirect,Http Headers,这是php中的simpleXML解析器的一部分 if (isset($_POST['lsr-submit'])) { header('Location: http://wft.com/customerentry.php'); } 问题是这将在几个服务器上,所以我需要一个相对路径customerentry.php,我忘记了这是如何完成的…使用头(“位置:http:/relative/path”) <?php if (isset($_POST['lsr-submit'])) {

这是php中的
simpleXML
解析器的一部分

if (isset($_POST['lsr-submit'])) {
    header('Location: http://wft.com/customerentry.php');
}
问题是这将在几个服务器上,所以我需要一个相对路径
customerentry.php
,我忘记了这是如何完成的…

使用
头(“位置:http:/relative/path”)

<?php

if (isset($_POST['lsr-submit']))
{
    header('Location: customerentry.php');
}
在代码中,它应该是

<?php
if (isset($_POST['lsr-submit'])){
    header('Location: http:/customerentry.php');
}

如果需要相对于当前路径的零件,可以执行以下操作:

if (isset($_POST['lsr-submit'])) {
    header('Location: customerentry.php');
}

如果您想要一个相对于站点根目录的部分,请以
/
开头URL:

if (isset($_POST['lsr-submit'])) {
    header('Location: /customerentry.php');
}

注: 尽管支持使用相对浏览器,但实际浏览器明确表示
位置
标题中给出的URL应该始终是绝对的,而不是相对的。因此,最好始终使用绝对URL,如下所示:

var $basePath = $_SERVER['HTTP_HOST'];
if (isset($_POST['lsr-submit'])) {
    header('Location: ' . $basePath . '/customerentry.php');
}

只需删除域名?