【问题标题】:How to replace GET parameters in URL如何替换 URL 中的 GET 参数
【发布时间】:2021-05-12 13:43:31
【问题描述】:

例如,如果我有一个 URL http://example.com/?src=example&test_28934

如何删除 ? 之后的所有内容,以便用户始终登陆 http://example.com

我已经尝试过了,并且 URL 保持不变。

$current_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url = reset((explode('?', $current_url)));

【问题讨论】:

标签: php url parameters get


【解决方案1】:

你应该检查这个https://www.php.net/manual/en/function.substr.php 还有这个Remove portion of a string after a certain character

对于您的示例,它将是

$current_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url = substr($current_url, 0, strpos($current_url, "?"));

【讨论】:

    【解决方案2】:

    header("位置:" . "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "?");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      相关资源
      最近更新 更多