I figure out how to pass $_SESSION values into Laravel project.
In my login.php page (non-laravel) I put a call to a route and send the information via POST.
$query = 'SELECT * FROM gvausers u inner join user_types ut on u.user_type_id = ut.user_type_id where activation=1 and callsign=? and password=?';
$stmt = $db->prepare($query);
$stmt->bind_param('ss', $user, $Encrypt_Pass);
$stmt->execute();
if (!$result = $stmt->get_result()) {
die('There was an error running the query [' . $db->error . ']');
}
$row_cnt = mysqli_num_rows($result);
if (!$row_cnt) {
header('Location: ./index.php?page=nosession');
} else {
while ($row = $result->fetch_assoc()) {
$user_type = $row['user_type_id'];
}
}
$_SESSION['access'] = true;
$_SESSION['usertype'] = $user_type;
$access = $_SESSION['access'];
$uri = 'http://admin.mysite.com/api/store-session';
$data = [
'access' => $access,
'usertype' => $user_type
];
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
In web.php route file, I put the route:
Route::post('/api/store-session', function (Request $request) {
session(['access' => $request->input('access')]);
session(['usertype' => $request->input('usertype')]);
return response()->json(['status' => 'Session stored']);
})->withoutMiddleware([VerifyCsrfToken::class]);
In my view I use the code:
@php
$access = session('access');
$usertype = session('usertype');
dd($access, $usertype);
@endphp
The problem now is:
When I do a dd(session('access')), for example, inside the route, I obtain the value stored in session. But when I try dd($access, $usertype) in my view, the value returns null.
How can I get the values of sessions inside my view?