我使用的是Laravel 5,我在/public/plugins/ckfinder目录中有引用ckfinder的文件夹。
CheckAuthentication函数在config.php中是我需要使用的,但是会话值和Auth是空的。
我试过了
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);
}
}发布于 2015-06-05 11:43:53
我也有同样的问题。对于Laravel4.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();
}这应该能行。
发布于 2019-01-27 02:22:48
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();
}发布于 2021-11-13 13:37:39
CKFinder 3 for PHP
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();
}
};https://stackoverflow.com/questions/30665618
复制相似问题