diff --git a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
index 3b200430a8c6e3b434de4aa704ab6f25446ac74d..cf58af4e8154d5a78c29fa4c184749c9ac052976 100644
--- a/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
+++ b/lib/SimpleSAML/Bindings/Shib13/HTTPPost.php
@@ -146,14 +146,39 @@ class SimpleSAML_Bindings_Shib13_HTTPPost {
 		# openssl req -new -key server.key -out server.csr
 		# openssl x509 -req -days 60 -in server.csr -signkey server.key -out server.crt
 		
-		$p = new SimpleSAML_XHTML_Template($this->configuration, 'post.php');
+
+		
+		
+		
+		if ($this->configuration->getValue('debug')) {
 	
-		$p->data['RelayStateName'] = 'TARGET';
-		$p->data['RelayState'] = $relayState;
-		$p->data['destination'] = $destination;
-		$p->data['response'] = base64_encode($response);
+			$p = new SimpleSAML_XHTML_Template($this->configuration, 'post-debug.php');
+			
+			$p->data['header'] = 'SAML (Shibboleth 1.3) Response Debug-mode';
+			$p->data['RelayStateName'] = 'TARGET';
+			$p->data['RelayState'] = $relayState;
+			$p->data['destination'] = $destination;
+			$p->data['response'] = str_replace("\n", "", base64_encode($response));
+			$p->data['responseHTML'] = htmlentities($responsedom->saveHTML());
+			
+			$p->show();
+
+		
+		} else {
+			
+			$p = new SimpleSAML_XHTML_Template($this->configuration, 'post.php');
+		
+			$p->data['RelayStateName'] = 'TARGET';
+			$p->data['RelayState'] = $relayState;
+			$p->data['destination'] = $destination;
+			$p->data['response'] = base64_encode($response);
+			
+			$p->show();
+
+		
+		}
+		
 		
-		$p->show();
 		/*