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

pentium's avatar

Getting error 419 even after using @csrf field after deployment of my laravel project on 000.webhostapp.com

I ran into a very critical solution and I can not find a solution on google. I am using Laravel 6 and everything works perfectly on my localhost. But, after deployment on 000.wbhostapp.com for every form I am using it is returning the 419 error (page expired) even though I have use the @csrf field. if you inspect the form you can see the that the CSRF field is present, but when you submit the form it returns the 419 error

0 likes
10 replies
Sinnbeck's avatar

Try regenerating the app key

php artisan key:generate
1 like
hemmy6894's avatar

Some time 000webhost not reading from .env file put all value of .env to its specific configuration file

example

APP_KEY = YOU_KEY

put it to config/app.php

find

"key" => env(APP_KEY,"")

and set it to

"key" => env(APP_KEY,base64_decode(YOUR_KEY))
pentium's avatar

I have run php artisan key:generate php artisan cache:config

and i also replace all the value in config/app.php with the corresponding value from .env file

pentium's avatar

what I have come to realize is that this error only occurs when I use the Post method. if I use Get method it works perfectly

Snapey's avatar

GET does not use csrf

Check that your browser is receiving the session cookie. You can look in developer tools

You should receive a cookie called appname_session where appname is your application name in .env

pentium's avatar

i just check it now and if i inspect the form field i can see the _token field with the value. but if i check the session cookie i cant find anything

Snapey's avatar
Snapey
Best Answer
Level 122

You MUST receive session cookie. If you don't then the csrf token will always be invalid.

If cookies are not being sent, then it is because you are sending some content to the browser in advance of the actual content. You need to look at all the files you modified and check for blank line or other character before the opening <?php in every class

1 like
pentium's avatar

Thanks a lot, you just save me from a nightmare. actually my helpers class was having a blank line before the opening tag <?php

WCaaan's avatar

@Snapey You are the best, I have been trying to resolve this problem for days finally came here searching and fixed the problem using your solution.

Please or to participate in this conversation.