str_replace从$ _SESSION中删除字符串

I save a reuested URI into a SESSION by using:

$_SESSION['uri'] = $_SERVER["REQUEST_URI"];

Now I have a form that will be submitted and in case of no entry the page should be reloaded with the information from the GET-parameters. So I usually thought to check if the stored URI already contains the String with the GET-parameters by simply using str_replace('&error=empty', '', $_SESSION['uri']); but it seems that this function does not work and I have no clue why.

Here is an example from the original code where the form is submitted:

if (isset($_POST['send']) === true && empty($_POST['suggestion'])) {
    if ( isset($_GET['error']) === true ) {
        header ('Location: '.$_SESSION['uri'].'withoutstringerror');
    } else {    
        header ('Location: '.$_SESSION['uri'].'&error=empty');
    }

The header-function is necessary because if the form will be submitted and there is no entry all the GET-parameters will be lost. That is why I have to store the original URI and use the header-function to keep the information. The problem with the code above is that when submitting the form and there is no entry it adds the &error=emptyagain. I thought it would be the best solution to check if there is already that string in the URI and replace it by using str_replace()

So what am I doing wrong?

Thanks in advance.

$_SESSION['uri'] = str_replace('&error=empty', '', $_SESSION['uri']);

I think you've just missed assigning the return value from str_replace() to your session variable. str_replace() doesn't modify the variable you pass in by parameter directly, it returns a new value, based on the function call.