try{
$query = "SELECT user_id FROM user WHERE username = '".$username."'";
$result = $dbhandle->query($query,PDO::FETCH_OBJ);
//$stmt->bindParam(":username",$username);
// $result = $stmt->fetchAll(PDO::FETCH_BOTH);
while($row = $result->fetch()){
$id = $row['user_id'];
$_SESSION['user_id'] = $id;
}
}catch(PDOException $e){ echo $e->getMessage();}
答案 0 :(得分:0)
您可以将此代码用作示例代码
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\JacobBennett\Pjax\PjaxMiddleware::class
];
希望这有帮助。