0

For example, if I have a URL http://example.com/?src=example&test_28934

How do I remove everything after ?, so the user always lands on http://example.com?

I have tried this and the URL stays the same.

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

2 Answers2

0

You should check this https://www.php.net/manual/en/function.substr.php and this Remove portion of a string after a certain character

For your example it will be

$current_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url = substr($current_url, 0, strpos($current_url, "?"));
miguelsantos69
  • 11
  • 1
  • 2
  • 5
-1

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