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

sadhakbj's avatar

Generating COOKIE / session from AJAX call

Hello all,

I need to generate cookie in my laravel app from an external AJAX call (from another app). This is my backend Laravel code:

    /**
     * @param $fingerPrint
     * @return \Illuminate\Http\JsonResponse
     */
    public function storeFingerPrint($fingerPrint)
    {
        header('Access-Control-Allow-Origin: *');
        if (request()->ajax()) {
            session()->put('device_finger_print', $fingerPrint);
            $fingerPrintCookie = Cookie::queue('device_finger_print', $fingerPrint, 120);
        }


        return response()->json(['print' => $fingerPrint]);
    }

When i try to access the cookie, I always get null.

Is there any solution to this ?

0 likes
0 replies

Please or to participate in this conversation.