From c0ce3f02ae56f4f3bc063b20c93c2dc193b35309 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 2 Dec 2009 11:51:44 +0000
Subject: [PATCH] Add code to detect whether the session cookie is set.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2014 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Session.php              | 14 ++++++++++++++
 lib/SimpleSAML/SessionHandler.php       | 14 ++++++++++++++
 lib/SimpleSAML/SessionHandlerCookie.php | 14 ++++++++++++++
 lib/SimpleSAML/SessionHandlerPHP.php    | 15 +++++++++++++++
 4 files changed, 57 insertions(+)

diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php
index 7ddd48b60..bc272c901 100644
--- a/lib/SimpleSAML/Session.php
+++ b/lib/SimpleSAML/Session.php
@@ -940,6 +940,20 @@ class SimpleSAML_Session {
 		return $this->logoutState;
 	}
 
+
+	/**
+	 * Check whether the session cookie is set.
+	 *
+	 * This function will only return FALSE if is is certain that the cookie isn't set.
+	 *
+	 * @return bool  TRUE if it was set, FALSE if not.
+	 */
+	public function hasSessionCookie() {
+
+		$sh = SimpleSAML_SessionHandler::getSessionHandler();
+		return $sh->hasSessionCookie();
+	}
+
 }
 
 ?>
\ No newline at end of file
diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php
index eee3b954a..562fed2b9 100644
--- a/lib/SimpleSAML/SessionHandler.php
+++ b/lib/SimpleSAML/SessionHandler.php
@@ -115,6 +115,20 @@ abstract class SimpleSAML_SessionHandler {
 		/* Set the session handler. */
 		self::$sessionHandler = $sh;
 	}
+
+
+	/**
+	 * Check whether the session cookie is set.
+	 *
+	 * This function will only return FALSE if is is certain that the cookie isn't set.
+	 *
+	 * @return bool  TRUE if it was set, FALSE if not.
+	 */
+	public function hasSessionCookie() {
+
+		return TRUE;
+	}
+
 }
 
 ?>
\ No newline at end of file
diff --git a/lib/SimpleSAML/SessionHandlerCookie.php b/lib/SimpleSAML/SessionHandlerCookie.php
index 06cd8a188..83a462315 100644
--- a/lib/SimpleSAML/SessionHandlerCookie.php
+++ b/lib/SimpleSAML/SessionHandlerCookie.php
@@ -117,6 +117,20 @@ extends SimpleSAML_SessionHandler {
 
 		return TRUE;
 	}
+
+
+	/**
+	 * Check whether the session cookie is set.
+	 *
+	 * This function will only return FALSE if is is certain that the cookie isn't set.
+	 *
+	 * @return bool  TRUE if it was set, FALSE if not.
+	 */
+	public function hasSessionCookie() {
+
+		return array_key_exists('SimpleSAMLSessionID', $_COOKIE);
+	}
+
 }
 
 ?>
\ No newline at end of file
diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php
index 80dab6254..40af336ac 100644
--- a/lib/SimpleSAML/SessionHandlerPHP.php
+++ b/lib/SimpleSAML/SessionHandlerPHP.php
@@ -93,6 +93,21 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler {
 
 		return $_SESSION[$key];
 	}
+
+
+	/**
+	 * Check whether the session cookie is set.
+	 *
+	 * This function will only return FALSE if is is certain that the cookie isn't set.
+	 *
+	 * @return bool  TRUE if it was set, FALSE if not.
+	 */
+	public function hasSessionCookie() {
+
+		$cookieName = session_name();
+		return array_key_exists($cookieName, $_COOKIE);
+	}
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab