在表单提交成功或失败时,我使用以下内容。生成的网址显示为http://example.com/directory/?success=false
我遇到的问题是,当用户在更正验证错误后再次尝试提交表单时,生成的URL变为http://example.com/directory/?success=false?success=true
- 我需要先清除任何查询字符串。我怎么能这样做?
PHP
# Redirect user to error message
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?success=false');
}
答案 0 :(得分:1)
您可以使用explode()
来破解$_SERVER['HTTP_REFERRER']
字符串以摆脱现有的$_GET
参数:
$bits = explode('?',$_SERVER['HTTP_REFERRER']);
$redirect = $bits[0];
# Redirect user to error message
header('Location: ' . $redirect . '?success=true');
答案 1 :(得分:0)
这样的事情怎么样:
$i = strchr($_SERVER['HTTP_REFERER'], "?");
$address = substr($_SERVER['HTTP_REFERER'], 0, $i);
header('Location: ' . $address . '?success=false');