The page has expired due to inactivity lỗi năm 2024

I'm new with Laravel, I am now using the latest version 5.6. Despite the version difference on this video I was able to work my way up to the Form Builder part of the course. I was working on:

the create.blade.php file with this code:

@extends['layouts.main'] @section['content'] List Title

@stop

and TodoListController.php code

public function create[] { return View['todos.create']; }

public function store[] {

return "Creating a New List";
//$list = new TodoList[];
//$list->name = "Another List";
//$list->save[];
}

However when I run the site I get a "The Page Has Expired Due to inactivity" Error.

Can anybody tell me what I'm doing wrong?

Thanks

1 Answer

Robert Anthony April 10, 2018 6:19pm

In your firm in the HTML file add a line which says:

This will probably fix it. The error is one I struggled with and it was due to the missing csrf token.

I access the site as: localhost:8000/

This is what I have in session.php:

'driver' => env['SESSION_DRIVER', 'file'],
'lifetime' => env['SESSION_LIFETIME', 120],
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path['framework/sessions'],
'connection' => null,
'table' => 'sessions',
'store' => null,
'lottery' => [2, 100],
'cookie' => env[
    'SESSION_COOKIE',
    str_slug[env['APP_NAME', 'laravel'], '_'].'_session'
],
'path' => '/',
'domain' => env['SESSION_DOMAIN', null],
'secure' => env['SESSION_SECURE_COOKIE', false],
'http_only' => true,
'same_site' => null,

and this is what I have in env file:

APP_NAME=xyz-xyz
APP_ENV=local
APP_KEY=base64:LhyBmW6dl3E6ZZ+nwClsmVa7ONHfTkl7Sl1vSxY9f44=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=//localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=xyz
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

If you’re getting[ ‘The page has expired due to inactivity. Please refresh and try again.’] error in your laravel project then follow the below steps to remove it.

Step1. Open your terminal/command prompt and run these commands in your project root.

  1. php artisan cache:clear
  2. php artisan config:clear
  3. php artisan route:clear
  4. php artisan view:clear,

Also, try to clear the browser cache along with running these commands.

After that, add the below code in your form method

Laravel 5.5 CRUD Tutorial, Introduction And Agenda Overview, Laravel Training Part – 1 DevopsSchool

... which was expected. But the problem was that I could not get rid of this message. I would go back one page, press "Ctrl + Shift + R" - and I would get this message again after submitting the form.

So refreshing didn't fix it.

I also tried to clean browser's cache, Laravel cache [php artisan cache:clear, php artisan config:clear, php artisan clear-compiled, php artisan route:clear, php artisan view:clear] - and it didn't work.

But when I closed and opened the browser - there was no more of that message, everything worked as it should.

Is this a bug? I'm worried about the end users of the website, if that happens to them ... they will be lost 🤔

i am trying to submit a form with some fields and showing this error “The page has expired due to inactivity. Please refresh and try again.” so when I look my form very carefully then i found that one CSRF token verification is missing.

  1. you have to do one thing add @csrf or {{ csrf_field[] }} in your form.
  2. and then run below command to clear your app cache

php artisan cache:clear
php artisan r:cache
php artisan view:clear

References :

Click Here

Laravel 5.5 CRUD Tutorial, Introduction And Agenda Overview, Laravel Training Part – 1 DevopsSchool

Senior Software Engineer at Cotocus

Email - contact@DevOpsSchool.com

Be a Full Stack Developer and eager to learn new Technology. Knowledge: CSS, Bootstrap, Javascript, PHP, WordPress, Joomla, Moodle, Laravel, AJAX, Jquery, Java, Dart, Flutter, Photoshop, CorelDraw, Pagemaker & Office Package

Chủ Đề