You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Termux开发Laravel网站:注册页面提交提示过期故障求助

Fixing Laravel "Page Expired" Error on Registration Form in Termux

Hey there, let's work through that frustrating "page expired" error you're getting when submitting your registration form in Termux. This issue almost always ties back to CSRF token validation or session configuration—here are the most actionable steps to resolve it:

1. Verify CSRF Token is Present in Your Form

Laravel requires a CSRF token to validate POST requests, so make sure your registration form includes this critical piece:

  • If using Blade templates, add the @csrf directive right inside your <form> tag:
    <form method="POST" action="/register">
        @csrf
        <!-- Your form fields here -->
    </form>
    
  • If you're not using Blade, manually insert the token field:
    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
    

2. Audit Your .env Configuration

Double-check these key settings in your .env file—misconfigurations here are a common culprit:

  • SESSION_DRIVER: The default file driver might hit permission issues in Termux. Try switching to cookie temporarily, or fix directory permissions with this command:
    chmod -R 755 storage/framework/sessions
    
  • APP_KEY: An missing or invalid APP_KEY breaks session encryption. Regenerate it with:
    php artisan key:generate
    
  • APP_URL: Ensure this matches the URL you use to access your site (e.g., http://localhost:8000). Mismatched URLs cause CSRF token domain validation failures.

3. Clear Laravel Caches and Sessions

Stale cached data can cause unexpected behavior. Run these commands in your Termux terminal to wipe old cache and session data:

php artisan cache:clear
php artisan config:clear
php artisan session:clear

You can also manually delete files in storage/framework/cache and storage/framework/sessions if needed.

4. Confirm Request Method and Route Alignment

Make sure your registration route is defined to accept POST requests, and your form uses the same method:

  • Check your routes/web.php file for something like:
    Route::post('/register', [RegistrationController::class, 'store']);
    
  • Ensure your form's method attribute is set to POST (not GET).

5. Check Termux System Time

A frequently overlooked issue: if Termux's system time is drastically out of sync with real time, Laravel's session expiration logic will malfunction.

  • Check current time with:
    date
    
  • Set the correct timezone (e.g., for Shanghai):
    timedatectl set-timezone Asia/Shanghai
    

If none of these steps resolve the issue, take a look at Laravel's error logs in storage/logs/laravel.log—they'll often reveal specific validation or session errors that aren't shown in the browser.

内容的提问来源于stack exchange,提问作者Rauz Saul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:31:32