From 634a496d01950b9ff791d3bc99accece43a3dd4f Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Mon, 05 Oct 2020 15:46:45 +0000
Subject: [PATCH] Fix session handling die to changes in PHP 7.1

---
 uphpCAS.php |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/uphpCAS.php b/uphpCAS.php
index 1633119..bfb2b69 100644
--- a/uphpCAS.php
+++ b/uphpCAS.php
@@ -14,6 +14,7 @@
 	protected $serverUrl = '';
 	protected $serviceUrl;
 	protected $sessionName = 'uphpCAS-user';
+	protected $sessionStarted = FALSE;
 	protected $method = 'POST';
 	protected $caFile = NULL;
 	
@@ -112,6 +113,23 @@
 		$this->caFile = $caFile;
 	}
 	
+	public function session_start() {
+		if($this->sessionStarted) {
+			return TRUE;
+		}
+		if(version_compare(PHP_VERSION, '7.1.0', '<')) {
+			@session_start();
+		} else {
+			if(!isset($_SESSION)) {
+				if(!session_start()) {
+					throw new RuntimeException('Cannot start session');
+				}
+			}
+		}
+		$this->sessionStarted = TRUE;
+		return TRUE;
+	}
+	
 	public function loginUrl() {
 		return $this->serverUrl.'/login?method='.$this->method
 			.'&service='.urlencode($this->serviceUrl);
@@ -123,7 +141,7 @@
 	}
 	
 	public function logoutLocal() {
-		@session_start();
+		$this->session_start();
 		unset($_SESSION[$this->sessionName]);
 	}
 	
@@ -139,11 +157,12 @@
 	}
 	
 	public function isAuthenticated() {
+		$this->session_start();
 		return isset($_SESSION[$this->sessionName]);
 	}
 	
 	public function authenticate() {
-		@session_start();
+		$this->session_start();
 		if($this->isAuthenticated()) {
 			return $_SESSION[$this->sessionName];
 		} elseif(isset($_REQUEST['ticket'])) {

--
Gitblit v1.9.1