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

nadinaa11's avatar

Page expired

Does someone know why after submitting the login form, page expires? This happens after i activated my csrf token from the verifycsrftoken.php. Yes, i do have <input type="hidden" name="_token" value="{{ csrf_token() }}" /> in my form. I tried everything. Thanks!

0 likes
49 replies
jlrdw's avatar

Does session folder have correct permissions to be written to?

Also do you see the token in the network tab?

1 like
nadinaa11's avatar

@jlrdw yes, it looks something like this: _token: 4pjhDBR40D7KNMq5T7QbJ5FcgJX6IVvurIM1AUoS and also i have this Status Code: 419 unknown status

jlrdw's avatar

@nadinaa11 try

<?php echo csrf_field(); ?>

Replace the whole input line. Or are you using blade?

If blade:

@csrf

Do you see session data in storage/framework/sessions

1 like
nadinaa11's avatar

@jlrdw yes, i am using blade. I replaced it and it is still not working... yes, i see session data. still not working after replacing with @csrf

nadinaa11's avatar

@jlrdw I did this too... when i disable the csrf, the user is not logging in. This is my function

` public function access_account(Request $request){ $this->validate($request, ['email' => 'email|required', 'password' => 'required' ]);

    $client = Client::where('email', $request->input('email'))->first();

    if($client){
        if(Hash::check($request->input('password'), $client->password)){
            Session::put('client', $client);
            return redirect('/shop');
        }
        else{
            return back()->with('status', 'Wrong email or password');
        }
    }
    else{
        return back()->with('status', 'You do not have an account with this email');
    }
`

also i use post method

jlrdw's avatar

@nadinaa11 in this piece of code:

        if(Hash::check($request->input('password'), $client->password)){
            Session::put('client', $client);
            return redirect('/shop');
        }

Put:

        if(Hash::check($request->input('password'), $client->password)){
            echo "hash is good";
            die;
            Session::put('client', $client);
            return redirect('/shop');
        }

Does it echo?

1 like
jlrdw's avatar

@nadinaa11 make sure you have the correct route and hitting correct method.

At the very top of the login method put:

dd("hit the method");

Check your routes, make sure you have the app key set, etc.

1 like
nadinaa11's avatar

@jlrdw my route is correct, app key set, still not working. Even after adding the dd i am receiving the same 419 page expired. i am going crazy

jlrdw's avatar

@nadinaa11 you cleared browser cache and view cache and config:clear?

Show your form.

1 like
nadinaa11's avatar

@jlrdw `

<div class="limiter">
	<div class="container-login100" style="background-image: url('frontend/login/images/bg-01.jpg');">
		<div class="wrap-login100">
			<form class="login100-form validate-form" action="{{url('/access_account')}}" method="POST">
				@csrf
				<a href="{{url('/')}}">
				<span class="login100-form-logo">
					<i class="zmdi zmdi-landscape"></i>
				</span>
			</a>
				<span class="login100-form-title p-b-34 p-t-27">
					Autentificare
				</span>
				@if (count($errors) > 0)
				<div class="alert alert-danger">
					<ul>
						@foreach ($errors->all() as $error)
							<li>{{$error}}</li>
						@endforeach
					</ul>
			@endif

			@if (Session::has('status'))
					<div class="alert alert-danger">
						{{Session::get('status')}}
					</div>
			@endif
				<div class="wrap-input100 validate-input" data-validate = "Enter username">
					<input class="input100" type="text" name="email" placeholder="Username">
					<span class="focus-input100" data-placeholder="&#xf207;"></span>
				</div>

				<div class="wrap-input100 validate-input" data-validate="Enter password">
					<input class="input100" type="password" name="password" placeholder="Password">
					<span class="focus-input100" data-placeholder="&#xf191;"></span>
				</div>

				<div class="container-login100-form-btn">
					<button class="login100-form-btn">
						Autentificare
					</button>
				</div>

`

jlrdw's avatar

@nadinaa11

Show the route for this:

And try replacing

 action="{{url('/access_account')}}"

with

action="{{ route('access_account') }}"

or

action="{{ '/access_account' }}"   // try this first.

with and without leading slash

You don't seem to be hitting the controller method.

nadinaa11's avatar

@jlrdw the route: Route::post('/access_account', [ClientController::class, 'access_account']); . replacing with action="{{ '/access_account' }}" has the same result: 419 page expired. also tried with or without the slash. replacing with action="{{ route('access_account') }}" is throwing an error which sounds like this: Route [/access_account] not defined. tried with and without the leading slash.

jlrdw's avatar

@nadinaa11 Did you import the ClientController into the routes file?

Are any routes working? and usually a method is written like:

accessAccount

instead of

access_account

just FYI

Can you make a method called myTest in the same class? Then make a get route to it: Then echo out something. Something is not setup correctly. Basically see if calling a method in a controller works.

    public function myTest()
    {

        echo "hello";
    }

route

Route::get('mytest', [ClientController::class, 'myTest']);

Try with and without leading slash. And make sure your routes are not cached in development.

Run route:clear if needed.

1 like
nadinaa11's avatar

Yes, the clientcontroller is imported. The rest of the routes are working, for example, in the same controller i have a similar function for creating an account, with the related route in web.php and that one is working. The thing is that it started working when i disabled the csrf for it's route (create account). Before disabling, it's behaviour was the same as acess_account's: 419 page expired. If i am disabling the csrf for the access_account, it is simply not logging in. i think there is a problem with the csrf and i simply can't find it . tried everything

jlrdw's avatar

@nadinaa11 you need the csrf protection.

Show your routes file, that method should at least be reached.

1 like
nadinaa11's avatar

@jlrdw actually, none of my clientcontroller functions are working, i tried your function and also tested some of mines and for every one of them says "page not found". this is mind blowing. here is also my addtocart function and i didn't know why not even the cart is working... what sould i do now?

jlrdw's avatar

@nadinaa11 Okay show that whole controller and your routes file, something is named wrong or something.

And if you are on Linux, it's case sensitive.

nadinaa11's avatar

@jlrdw ClientController.php `<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request; use App\Models\Slider; use App\Models\Product; use App\Models\Category; use App\Models\Client; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Auth; use App\Cart; use Session;

class ClientController extends Controller { public function home(){

    $sliders = Slider::All()->where('status', 1);

    $products = Product::All()->where('status', 1);


    return view('client.home')->with('sliders', $sliders)->with('products', $products);
}

public function shop(){


    $categories = Category::All();

    $products = Product::All()->where('status', 1);


    return view('client.shop')->with('categories', $categories)->with('products', $products);   
}

public function myTest()
{

    echo "hello";
}

public function checkout(){
    if(!Session::has('client')){
        return view('client.login');
    }
    return view('client.checkout');
}

public function login(){
    return view('client.login');
}

public function logout(){
    Session::forget('client');

    return redirect('/shop');
}


public function signup(){
    return view('client.signup');
}
public function create_account(Request $request){
    $this->validate($request, ['email' => 'email|required|unique:clients',
                               'password' => 'required|min:4' ]);

    $client = new Client();
    $client->email = $request->input('email');
    $client->password = bcrypt($request->input('password'));

    $client->save();

    return back()->with('status', 'Your account has been succesfully created');
}

public function access_account(Request $request){
    $this->validate($request, ['email' => 'email|required',
                               'password' => 'required' ]);

    $client = Client::where('email', $request->input('email'))->first();

    if($client){
        if(Hash::check($request->input('password'), $client->password)){
            Session::put('client', $client);
            return redirect('/shop');
        }
        else{
            return back()->with('status', 'Wrong email or password');
        }
    }
    else{
        return back()->with('status', 'You do not have an account with this email');
    }

}


public function orders(){
    return view('admin.orders');
}

public function addtocart($id){
    $product = Product::find($id); 
    
    $oldCart = Session::has('cart')? Session::get('cart'):null;
    $cart = new Cart($oldCart);
    $cart->add($product, $id);
    Session::put('cart', $cart);

    //dd(Session::get('cart'));
    return back();
    
}
public function cart(){
    if(!Session::has('cart')){
        return view('client.cart');
    }

    $oldCart = Session::has('cart')? Session::get('cart'):null;
    $cart = new Cart($oldCart);

    return view('client.cart', ['products' => $cart->items]);
}

} `

nadinaa11's avatar

@jlrdw i am not using linux. posted the controller and web.php as comments to the main question

nadinaa11's avatar

web.php `<?php

use Illuminate\Support\Facades\Route; use App\Http\Controllers\ClientController; use App\Http\Controllers\AdminController; use App\Http\Controllers\CategoryController; use App\Http\Controllers\SliderController; use App\Http\Controllers\ProductController;

/* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/admin', function() { return view('welcome'); });

Route::get('/dashboard', function () { return view('admin.dashboard'); })->middleware(['auth'])->name('dashboard');

require DIR.'/auth.php';

//Route::get('/admin', [AdminController::class, 'admin']); Route::get('/mytest', [ClientController::class, 'myTest']);

Route::get('/addcategory', [CategoryController::class, 'addcategory']);

Route::get('/categories', [CategoryController::class, 'categories']);

Route::get('/savecategory', [CategoryController::class, 'savecategory']);

Route::get('/edit_category/{id}', [CategoryController::class, 'edit_category']);

Route::get('/updatecategory', [CategoryController::class, 'updatecategory']);

Route::get('/delete_category/{id}', [CategoryController::class, 'delete_category']);

Route::get('/addslider', [SliderController::class, 'addslider']);

Route::get('/sliders', [SliderController::class, 'sliders']);

Route::post('/saveslider', [SliderController::class, 'saveslider']);

Route::get('/edit_slider/{id}', [SliderController::class, 'edit_slider']);

Route::post('/updateslider', [SliderController::class, 'updateslider']);

Route::get('/delete_slider/{id}', [SliderController::class, 'delete_slider']);

Route::get('/activate_slider/{id}', [SliderController::class, 'activate_slider']);

Route::get('/unactivate_slider/{id}', [SliderController::class, 'unactivate_slider']);

Route::get('/addproduct', [ProductController::class, 'addproduct']);

Route::get('/products', [ProductController::class, 'products']);

Route::post('/saveproduct', [ProductController::class, 'saveproduct']);

Route::get('/edit_product/{id}', [ProductController::class, 'edit_product']);

Route::post('/updateproduct', [ProductController::class, 'updateproduct']);

Route::get('/delete_product/{id}', [ProductController::class, 'delete_product']);

Route::get('/activate_product/{id}', [ProductController::class, 'activate_product']);

Route::get('/unactivate_product/{id}', [ProductController::class, 'unactivate_product']);

Route::get('/view_product_by_category/{category_name}', [ProductController::class, 'view_product_by_category']);

Route::get('/orders', [ClientController::class, 'orders']);

Route::get('/', [ClientController::class, 'home']);

Route::get('/shop', [ClientController::class, 'shop']);

Route::get('/addtocart/{id}', [ClientController::class, 'addtocart']);

Route::get('/cart', [ClientController::class, 'cart']);

Route::get('/checkout', [ClientController::class, 'checkout']);

Route::get('/login1', [ClientController::class, 'login']);

Route::get('/signup', [ClientController::class, 'signup']);

Route::post('/access_account', [ClientController::class, 'access_account']);

Route::post('/create_account', [ClientController::class, 'create_account']);

Route::get('/logout', [ClientController::class, 'logout']);

// Route::get("/dashboard", function () { // return view("dashboard"); // })->middleware(["auth"])->name("dashboard");

// require DIR."/auth.php"; `

jlrdw's avatar

@nadinaa11 the route looks correct. Is the actual name of that controller ClientController? Not something like Clientcontroller or clientController?

There is something causing that class not being called, so check your spelling, caps, etc. You said you couldn't even reach the myTest method, correct?

What shows in network tab?

1 like
nadinaa11's avatar

@jlrdw yes, that is the correct name, ClientController. for the myTest i am receiving "page not found", actually i am receiving this for more methods, but not for all of them.

jlrdw's avatar

@nadinaa11 a final suggestion.

  • backup that controller
  • delete all methods
  • place one at a time
  • try the myTest first
  • if that works place another of your methods
  • keep adding methods

If the first one don't work, do same with routes, backup and place one at a time or a few at a time until again you have a problem. It will help narrow it down.

Also check the error logs.

Something is off somewhere. I looked over the code, but unless my eyes missed something it should be working.

Edit

I also suggest this series:

https://laracasts.com/series/laravel-8-from-scratch

And learn and use laravel conventions. But the above route should work. unless this require DIR.'/auth.php'; is a problem.

2 likes
nadinaa11's avatar

@jlrdw thank you so much!! i'll try tomorrow morning and give a feedback. :)

1 like
nadinaa11's avatar

@jlrdw feedback for your final suggestions: stil not working, receiving the same 419 page expired error for access_account

jlrdw's avatar

@nadinaa11 double, even triple check that sessions are working. I even duplicated as much of that application as I could and everything worked. Meaning the route, View, and controller. I did not need the model just to test a method.

Double check your logs for any errors.

Make sure the session config file is default, see if you changed something.

Is the session driver still set to file. Your code should at least get you to that method.

One more thing you can test, but let me know in a reply when you are ready.

nadinaa11's avatar

@jlrdw how do i exactly check if my sessions and logs are working?yes, Session driver is set to file.

nadinaa11's avatar

@jlrdw also i tried creating a new project just for testing a new log in method and i am receiving the same eror 419 page expired …

MohamedTammam's avatar

Increase your session lifetime by adding SESSION_LIFETIME to your .env with the number of minutes. Add something big like one day

SESSION_LIFETIME=1440

Add your domain to .env

SESSION_DOMAIN=myapp.local

Clear your cache

php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:clear

Make sure that you're sending the CSRF in the request (Check network tab).

And DO NOT disable CSRF at any case.

More options: https://stackoverflow.com/a/71542495

1 like
Snapey's avatar

web server is apache?

Do you see cookies in your browser (chrome developer tools, application tab)?

iftekhs's avatar

If any of the solutions above don't work then as an alternative maybe you can disable csrf for that specific route if you don't need it.

nadinaa11's avatar

@iftekhs the route is not working when i disable the csrf, it is simply not logging the user in

jlrdw's avatar

@nadinaa11 I gave another reply above. Also you said:

it is simply not logging the user in

But wait, yesterday I thought you were not getting to any methods in that controller. Is that still true?

Right now a login is not the issue, having that controller working I believe is still the issue, is that correct?

nadinaa11's avatar

@jlrdw i checked every method in my ClientController and the ones that are not working are the ones using sessions. The main problem is that I am still receiving 419 page expired for login methods and addtocart is not reacting. As i mentioned, these methods are using sessions.

jlrdw's avatar

@nadinaa11 try putting those routes in auth middleware.

But now methods that don't use session are working?

Is any other controller method that needs session working? I still think your sessions aren't persisting.

Snapey's avatar

so focus on the fact that sessions are not working and that it's nothing to do with csrf

iftekhs's avatar

@nadinaa11 I know it's weird to say this but can you check if you have an empty space in your .env file that might have caused the issue also you can try running php artisan config:clear.

Snapey's avatar

@nadinaa11 The most common cause is a stray character before the opening <?php in one of your files, or making the mistake of closing php near the bottom of a class file ?>

This prevents cookies from being sent to the client.

But you say there are cookies. Delete them and then try logging in again. Make sure the cookies are created fresh. There should be one for the laravel session

nadinaa11's avatar

UPDATE Error solved I switched xampp to mamp and voila, everything works fine.

Please or to participate in this conversation.