heroku laravel页面您要提交的信息不安全,稍后部署时出现419页面过期错误

83qze16e  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(125)

我在heroku上部署了一个laravel项目。当我提交表单时,它会打开,它最初说“您要提交的信息不安全”,如果我仍然提交它,它会说“419页已过期”
我尝试了很多解决方案我的表格样本是

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>Upload File</title>
    
</head>
<body>

    <!-- store route as action -->
    <div class="container">
            <div class="row">
                <div class="col-12">

                <br><br><br>
    <form action="{{route('video')}}" method="post" enctype="multipart/form-data">
        @csrf
        {{ csrf_field() }}
        <input type="file" class="form-control" name="videothing" id="videotitle" accept=" video/*">
        <input type="submit" class="btn btn-sm btn-block btn-danger" value="Upload" onclick="spinner()">
    </form>
    
        
    @if (session('message'))
    <h1 id="v">{{ session('message') }}</h1>
@endif

字符串
Laravel 419 Page Expired on production server. [ framework : Laravel | version : 7.5.2 ]Laravel 6 Showed 419 | page expired的数据库
我跟踪了这些链接,当我评论

\App\Http\Middleware\VerifyCsrfToken::class,


在kernel.php中,错误停止,但在提交表单时,它不会重定向到路由,而只是重新加载页面,我相信这是CSRF问题,但无法解决它
在我的VerifyCsrfToken.php中,我确实包含了

protected $except = [
        //
        'https://laraveluploading.herokuapp.com/',
        'https://laraveluploading.herokuapp.com/video',
    ];


我的session.php

<?php

use Illuminate\Support\Str;

return [

   

    'driver' => env('SESSION_DRIVER', 'file'),

    'lifetime' => env('SESSION_LIFETIME', 120),

    'expire_on_close' => false,

   
    'encrypt' => false,

   
    'files' => storage_path('framework/sessions'),

    
    'connection' => env('SESSION_CONNECTION', 'mysql'),

    
    'table' => 'sessions','books','videos',

    'store' => env('SESSION_STORE', null),

    'lottery' => [2, 100],

   

    'cookie' => env(
        'SESSION_COOKIE',
        Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
    ),

    

    'path' => '/',

    'domain' => env('SESSION_DOMAIN', 'https://laraveluploading.herokuapp.com'),

    

    'secure' => env('SESSION_SECURE_COOKIE',false),

    'http_only' => true,

    'same_site' => 'lax',

];


我的web.php有

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Exceptions\Handler;
use Symfony\Component\Debug\Exception\FatalThrowableError;
/*
|--------------------------------------------------------------------------
| 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('/', function () {
    
    return view('welcome');
})->name("start");

Route::post('/upload', function (Request $request) {
   try{
    if($request->file("thing")=="")
    {
        // return back()->withInput();
        return redirect()->route('start')->with('message', 'Insert Data!');
    }
    else
    {
        $name=$request->file("thing")->getClientOriginalName();
        $book=DB::table('books')->where('Title',$name)->count();
        if($book>0)
        {
        return redirect()->route('start')->with('message', 'Document already exists!');

        }
        else{
            $lang=$request->input("lang");
            $cato=$request->input("catogory");
            Storage::disk("google")->putFileAs("",$request->file("thing"),$name);
            $url=Storage::disk('google')->url($name);
            $details=Storage::disk("google")->getMetadata($name);
            $path=$details['path'];
            DB::insert('insert into books (Title, Catogory, Language, Url, FileId) values (?,?,?,?,?)', [$name,$cato,$lang,$url,$path]);
            return redirect()->route('start')->with('message', 'Successfully uploaded document, you have recieved token!');
        }
    }
}
catch(Throwable $e)
{
    return redirect()->route('start')->with('message', 'some error occured');
}
    
})->name("upload");

Route::get('/video', function(){
    return view('showvideo');
})->name("startvideo");

Route::post('/video', function (Request $request) {
    try{
     if($request->file("videothing")=="")
     {
         // return back()->withInput();
         return redirect()->route('startvideo')->with('message', 'Insert video!');
     }
     else
     {
         $videoname=$request->file("videothing")->getClientOriginalName();
         $video=DB::table('videos')->where('video_name',$videoname)->count();
         if($video>0)
         {
         return redirect()->route('startvideo')->with('message', 'Video name already exists!');
 
         }
         else{
            //  $lang=$request->input("lang");
            //  $cato=$request->input("catogory");
             Storage::disk("google")->putFileAs("",$request->file("videothing"),$videoname);
             $videourl=Storage::disk('google')->url($videoname);
            //  $videodetails=Storage::disk("google")->getMetadata($videoname);
            //  $path=$details['path'];
             DB::insert('insert into videos (video_name, video_url) values (?,?)', [$videoname,$videourl]);
             return redirect()->route('startvideo')->with('message', 'Successfully uploaded video');
         }
     }
 }
 catch(Throwable $e)
 {
     return redirect()->route('startvideo')->with('message', 'Some error occured in video uploading');
 }
     
 })->name("video");


在Heroku上的应用程序配置变量中,我添加了数据库credendtials(在Azure上)以及与Google Drive连接所需的Google客户端ID,密钥,刷新令牌。
我尝试了不同的链接,但没有用。请帮我解决这个问题。

izkcnapc

izkcnapc1#

我也有同样的问题,刚刚解决了这个问题。请尝尝这个
在AppServiceProvider.php中

public function boot() {
    if(config('app.env') === 'production') {
        URL::forceScheme('https');
    }
}

字符串
希望这能帮到你。

相关问题