我有以下两个应用程序:
- 在 CorePHP 中的应用
- 在 Laravel 中的应用
我想访问从 CorePHP 应用程序到 Laravel 应用程序的 session 。
为此,我使用了以下过程:
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
use Closure;
use Illuminate\Support\Facades\Session;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\HttpFoundation\Response;
class UserAuthenticateMiddleware extends Middleware {
public function handle($request, Closure $next) {
foreach(Session::all() as $key => $value)
{
$_SESSION[$key] = $value;
}
print_r($_SESSION);
}
}
但是,我收到以下错误:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
Type error: Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /home/dixon/php7esupport/esupport/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php
此问题的可能原因是什么?
最佳答案
除非您没有展示整个函数,否则您会忘记 return $next($request);
所以它会是这样的:
public function handle($request, Closure $next) {
foreach(Session::all() as $key => $value){
$_SESSION[$key] = $value;
}
return $next($request);
}
关于php - 在 Laravel 应用程序中访问核心 PHP 应用程序 session 时遇到的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50344184/