laravel 5 的 CKFinder 身份验证问题

CKFinder Authentication issue with laravel 5

我正在使用 Laravel 5。我在 /public/plugins/ckfinder 目录中有引用 ckfinder 的文件夹。

我需要使用 config.php 中的 CheckAuthentication 函数,但会话值和 Auth Class 为空。

我试过了

function CheckAuthentication(){
    return Auth::check();
}

 //Ckfinder Config.php
function CheckAuthentication(){
        if($_SESSION['ckfinder_enabled'] == 'enabled') {
            return true;
        } else {
            return false;
        }
    }

        //App\Http\Middleware\Authenticate.php
    public function handle($request, Closure $next)
            {
                if ($this->auth->guest()){
                        if ($request->ajax()){
                            return response('Unauthorized.', 401);
                        }else{
                            return redirect()->guest('auth/login');
                        }
                    }

                if($this->auth->check()) {
                     $_SESSION['ckfinder_enabled'] = 'enabled';
                    return $next($request);
                }
            }

我也遇到了同样的问题。您的代码对 laravel 4.2 很有用,但对于 laravel 5 您需要在 ckfinder 文件夹的 config.php:

中执行此操作
require _DIR_.'/../../../bootstrap/autoload.php';
$app = require_once _DIR_.'/../../../bootstrap/app.php';

$app->make('Illuminate\Contracts\Http\Kernel')
  ->handle(Illuminate\Http\Request::capture());

然后您就可以开始使用此代码了:

function CheckAuthentication(){
    return Auth::check();
}

这应该有效。

Laravel 5.7+:

require  $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
$app = require_once  $_SERVER['DOCUMENT_ROOT']. '/../bootstrap/app.php';
$response = $app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$cookie = $_COOKIE[$app['config']['session']['cookie']] ?? false;
if ($cookie) {
    $id = $app['encrypter']->decrypt($cookie, false);
    $session = $app['session']->driver();
    $session->setId($id);
    $session->start();
}

if (!$app['auth']->check()){
    header('HTTP/1.0 403 Forbidden'); exit();
}

PHP

的 CKFinder 3

Laravel v7.30.4

适合我

use Illuminate\Support\Facades\Auth;

$config['authentication'] = function () {
  require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
  $app = require_once  $_SERVER['DOCUMENT_ROOT']. '/bootstrap/app.php';
  $request = Illuminate\Http\Request::capture();
  $request->setMethod('GET');
  $app->make('Illuminate\Contracts\Http\Kernel')->handle($request);
  if (Auth::check() && Auth::user()->is_admin ) {
    return true;
  } else {
    header('HTTP/1.0 403 Forbidden');
    exit();
  }
};