I’ve been trying to understand how slim works. I want to know how to start session on a certain user type logs in. Please help me this is my final requirement.
You could start with this Slim tutorial to get the basics.
I want to know how to start session on a certain user type logs in.
Make sure, that the session is getting started for each request. For this purpose the best would be to start the session within a Middeware.
Example file: src/Middleare/SessionMiddleware .php
<?php
namespace App\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
final class SessionMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
$response = $handler->handle($request);
session_write_close();
return $response;
}
}