现在,有一个页面重定向使用
标题(“位置:{$_SERVER‘’HTTP_REFERER‘}”);
但是,页面重定向到的URL如下所示:
http://localhost:5110/page.php?1st=2&2nd=140413&3rd=547859如何删除重定向的URL的一部分?URL应该类似于:
http://localhost:5110/page.php?1st=2&3rd=547859如果你有其他建议告诉我..。谢谢。
发布于 2013-04-14 17:11:47
$referer = parse_url($_SERVER['HTTP_REFERER']);
parse_str($referer['query'], $query);
unset($query['2nd']); // unset the desired element
$referer['query'] = http_build_query($query);
$url = '';
if (array_key_exists('scheme', $referer)) { $url .= "{$referer['scheme']}://"; }
if (array_key_exists('host', $referer)) { $url .= $referer['host']; }
if (array_key_exists('port', $referer)) { $url .= ":{$referer['port']}"; }
if (array_key_exists('path', $referer)) { $url .= $referer['path']; }
if (array_key_exists('query', $referer)) { $url .= "?{$referer['query']}"; }
if (array_key_exists('fragment', $referer)) { $url .= "#{$referer['fragment']}"; }
header("Location: $url");发布于 2013-04-14 16:54:14
$ref = explode("?",$_SERVER['HTTP_REFERER']);
parse_str($ref[1], $qs);
unset($qs['query param to remove']);
$qs = http_build_query($qs);
$ref = $ref[0].'?'.$qs;发布于 2013-04-14 16:54:46
试试这个:
$str = 'http://localhost:5110/page.php?1st=2&2nd=140413&3rd=547859';
echo remove_qs_key($str,"2nd");
function remove_qs_key($url, $key) {
$url = preg_replace('/(?:&|(\?))' . $key . '=[^&]*(?(1)&|)?/i', "$1", $url);
return $url;
}结果:http://localhost:5110/page.php?1st=2&3rd=547859
https://stackoverflow.com/questions/16001387
复制相似问题