Skip to content

Commit a32d3da

Browse files
committed
Merge pull request #431 from Lusitanian/better-session-detection
Better session detection
2 parents a48f63c + 05238f3 commit a32d3da

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/OAuth/Common/Storage/Session.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
$sessionVariableName = 'lusitanian-oauth-token',
3737
$stateVariableName = 'lusitanian-oauth-state'
3838
) {
39-
if ($startSession && !isset($_SESSION)) {
39+
if ($startSession && !$this->sessionHasStarted()) {
4040
session_start();
4141
}
4242

@@ -185,4 +185,20 @@ public function __destruct()
185185
session_write_close();
186186
}
187187
}
188+
189+
/**
190+
* Determine if the session has started.
191+
* @url http://stackoverflow.com/a/18542272/1470961
192+
* @return bool
193+
*/
194+
protected function sessionHasStarted()
195+
{
196+
// For more modern PHP versions we use a more reliable method.
197+
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
198+
return session_status() != PHP_SESSION_NONE;
199+
}
200+
201+
// Below PHP 5.4 we should test for the current session ID.
202+
return session_id() !== '';
203+
}
188204
}

0 commit comments

Comments
 (0)