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

MyBraveShine's avatar

How to fix assosiate array key missing in json response in shared host?

I've had this issues for some reason, then I've changed my method, now I'm facing this issue again.

So Here's the code for response :

return Response([

    'token' => $token,

    'status' => 'success',

    'message' => 'loggedIn',

    'user' => new MeResource($user),

], 200)->withCookie($cookie);

And in return when I deploy project to shared host, token key is missing, like below :

{

    'ey... token',

    'status' : 'success',

    'message' : 'loggedIn',

    'user' : {...userinfo},

}

So as yo can see for some reason, the token key is missing/dropped.

In other hand I've said i had this issue days ago and in that case, I've had another field to return, and same thing happened, but I've tested some thing, and I've realized for some reason if value of key, got multiple underscores (_), key will be dropped from array.

Helpful info : Laravel Passport : ^11.3 Laravel : ^9.2 PHP : 8.1.4

0 likes
5 replies
LaryAI's avatar
Level 58

It sounds like the issue is related to the shared hosting environment. It's possible that the hosting provider has some sort of security feature that is stripping out the token key from the response. You could try contacting the hosting provider to see if they can provide any insight into the issue.

If that doesn't work, you could try changing the key name from token to something else, such as access_token. If the issue is related to the underscores, then this should fix the problem.

return Response([

    'access_token' => $token,

    'status' => 'success',

    'message' => 'loggedIn',

    'user' => new MeResource($user),

], 200)->withCookie($cookie);
MyBraveShine's avatar

@LaryAI I'm asnwering this, since people might do same suggestion, and It's not related to the key name, because, as I said, I've tried this before with different key name and etc.

adityakunhare's avatar

@mybraveshine First of all, print the data using http client if it is working on localhost. Else check the php version of shared hosting and your localhost is same.

MyBraveShine's avatar

@adityakunhare well I've done a few tests, and now when I test with postman, I can get token key, but in flutter, token key is dropped.

Also same PHP version in shared host, this token key was working before.

adityakunhare's avatar

@MyBraveShine If it is working in Http client, then you must check your flutter code, there might be something missing regarding the token

Please or to participate in this conversation.