Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Brainmaniac's avatar

`header("Location: " . $url);` does not work with Laravel Sail

Hi,

I got tired of Valet messing with me so I changed to Sail yesterday. I have a Stripe checkout intgration on my site.

Now I have a problem. There is one step, when my site is taking the user to the checkout hosted on stripe, that does not work any more..

Here is the code:

public function stripeCheckout(Request $request)
    {
        Stripe::setApiKey(config('app.stripe_secret_key'));
        header('Content-Type: application/json');

        $checkout_session = \Stripe\Checkout\Session::create([
            'line_items' => [[
                # Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
                'price' => $request->price_id,
                'quantity' => 1,
            ]],
            'mode' => 'payment',
            'success_url' => config('app.url') . 'purchase?session_id={CHECKOUT_SESSION_ID}',
            'cancel_url' => config('app.url') . 'purchase/canceled',
        ]);

        header("HTTP/1.1 303 See Other");
        header("Location: " . $checkout_session->url);
    }

Before this code has redirected me to $checkout_session->url. Not any more. I have validated that the $checkout_session->url is valid. It is.

As a workaround I have added a return redirect($checkout_session->url) below the header and now it works. Why did this behavior change when starting to use sail?

0 likes
1 reply
vincent15000's avatar

I don't understand why you should have to use header() given that Laravel has a redirect() helper. Sure it's PHP, but you should take advantage of the Laravel functionalities.

Please or to participate in this conversation.