diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php
index b8e9c285cc6f7a94e6e017bb9b8c0bcb9fd0a655..88775555d022284b9c4b918862c1dc74a4a7ad84 100644
--- a/lib/SimpleSAML/XHTML/IdPDisco.php
+++ b/lib/SimpleSAML/XHTML/IdPDisco.php
@@ -351,6 +351,19 @@ class SimpleSAML_XHTML_IdPDisco {
 	}
 
 
+	/**
+	 * Save the current IdP choice to a cookie.
+	 *
+	 * @param string $idp  The entityID of the IdP.
+	 */
+	protected function setPreviousIdP($idp) {
+		assert('is_string($idp)');
+
+		$this->log('Choice made [' . $idp . '] Setting cookie.');
+		$this->setCookie('lastidp', $idp);
+	}
+
+
 	/**
 	 * Determine whether the choice of IdP should be saved.
 	 *
@@ -380,9 +393,7 @@ class SimpleSAML_XHTML_IdPDisco {
 		$idp = $this->getSelectedIdP();
 		if($idp !== NULL) {
 			/* The user selected this IdP. Save the choice in a cookie. */
-
-			$this->log('Choice made [' . $idp . '] Setting cookie.');
-			$this->setCookie('lastidp', $idp);
+			$this->setPreviousIdP($idp);
 
 			if($this->saveIdP()) {
 				$this->setCookie('remember', 1);