Skip to content

Commit a779436

Browse files
committed
get user from session, prevent double start session
1 parent 5bb231a commit a779436

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Api/Solid.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Pdsinterop\PhpSolid\Server;
55
use Pdsinterop\PhpSolid\ClientRegistration;
66
use Pdsinterop\PhpSolid\User;
7+
use Pdsinterop\PhpSolid\Session;
78

89
class Solid {
910
public static function respondToJwks() {
@@ -19,6 +20,8 @@ public static function respondToWellKnownOpenIdConfiguration() {
1920
}
2021

2122
public static function respondToAuthorize() {
23+
$user = User::getUser(Session::getLoggedInUser());
24+
2225
$clientId = $_GET['client_id'];
2326
$getVars = $_GET;
2427

@@ -146,6 +149,7 @@ public static function respondToRegister() {
146149
}
147150

148151
public static function respondToSharing() {
152+
$user = User::getUser(Session::getLoggedInUser());
149153
$clientId = $_POST['client_id'];
150154
$userId = $user['userId'];
151155
if ($_POST['consent'] === 'true') {

lib/Session.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
class Session {
55
private $cookieLifetime = 24*60*60;
66
public static function start($username) {
7-
session_start([
8-
'cookie_lifetime' => 24*60*60 // 1 day
9-
]);
7+
if (session_status() === PHP_SESSION_NONE) {
8+
session_start([
9+
'cookie_lifetime' => 24*60*60 // 1 day
10+
]);
11+
}
1012
$_SESSION['username'] = $username;
1113
}
1214

1315
public static function getLoggedInUser() {
14-
session_start();
16+
if (session_status() === PHP_SESSION_NONE) {
17+
session_start();
18+
}
1519
if (!isset($_SESSION['username'])) {
1620
return false;
1721
}

0 commit comments

Comments
 (0)