Home > Back-end >  header Location is going back to the same POST URL it came from
header Location is going back to the same POST URL it came from

Time:12-24

For some reason, my header("Location: <url>") is getting redirected to the same POST url it came from. I had to switch to echo a javascript redirect to make it work for the time-being.

catch (Exception $e)
{            
    switch (get_class($e))
    {
        case 'ValidationError':
            $_SESSION['FLASH_ERROR'] = $e->getMessage();
            $location = CB_ABS_URI."upgrade?ID=".$_GET['ID']."&package=".$_POST['plan'];
            # die("You're getting redirected ... <script type='text/javascript'>setTimeout('redirect()',0); function redirect() { window.location = '$location'; }</script>");
            header("Location:", $location);
            exit;
        break;
        default:
            # die
        break;
    }            
}

CodePudding user response:

I think its a typo.

header("Location:", $location);

Should be

header("Location: ". $location);

You had a comma in the header function. If you add a comma in the header function your setting the replace parameter in that function as mentioned on php.net

  • Related