diff --git a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
index 3e9775ad2e92aff57ec605a5c3be59a1de4016ee..8d5fc5e367f969678019dccd72a4ed7fea2c8851 100644
--- a/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
+++ b/lib/SimpleSAML/Bindings/SAML20/HTTPRedirect.php
@@ -12,6 +12,7 @@
  */
  
 require_once('SimpleSAML/Configuration.php');
+require_once('SimpleSAML/Utilities.php');
 require_once('SimpleSAML/XML/MetaDataStore.php');
 require_once('SimpleSAML/XHTML/Template.php');
 
@@ -79,8 +80,7 @@ class SimpleSAML_Bindings_SAML20_HTTPRedirect {
 		
 		} else {
 
-			header("Location: " . $redirectURL);
-
+			SimpleSAML_Utilities::redirect($redirectURL);
 		
 		}
 
diff --git a/www/auth/login-auto.php b/www/auth/login-auto.php
index b045668836bf5f6fb69922ba3827b022fd80dbad..b2352c748fab156d28d3727a34588bdff816764f 100644
--- a/www/auth/login-auto.php
+++ b/www/auth/login-auto.php
@@ -91,6 +91,6 @@ $session->setAttributes($attributes);
 
 /* Return the user to the page set in the RelayState parameter. */
 $returnto = $_REQUEST['RelayState'];
-header("Location: " . $returnto);
+SimpleSAML_Utilities::redirect($returnto);
 
 ?>
diff --git a/www/auth/login-ldapmulti.php b/www/auth/login-ldapmulti.php
index 145de7c96da49d93f45aea02e066f7fc360481a8..a154ec10a7fb8246d91bd89e53e1e565e9a24080 100644
--- a/www/auth/login-ldapmulti.php
+++ b/www/auth/login-ldapmulti.php
@@ -88,8 +88,7 @@ if (isset($_POST['username'])) {
 			$session->setNameIDFormat('urn:oasis:names:tc:SAML:2.0:nameid-format:transient');
 			
 			$returnto = $_REQUEST['RelayState'];
-			header("Location: " . $returnto);
-			exit(0);
+			SimpleSAML_Utilities::redirect($returnto);
 
 		}
 	// ldap_close() om du vil, men frigjoeres naar skriptet slutter
diff --git a/www/auth/login-radius.php b/www/auth/login-radius.php
index 47dc0efff95e2757e5b347754ce08ff445545740..50603545eec6f4bff979a34987b0bb9686846992 100644
--- a/www/auth/login-radius.php
+++ b/www/auth/login-radius.php
@@ -53,10 +53,9 @@ if (isset($_POST['username'])) {
 				
 				$session->setAuthenticated(true);
 				$session->setAttributes($attributes);
+
 				$returnto = $_REQUEST['RelayState'];
-				header("Location: " . $returnto);
-				
-				exit(0);
+				SimpleSAML_Utilities::redirect($returnto);
 				
 	
 			case RADIUS_ACCESS_REJECT:
diff --git a/www/auth/login.php b/www/auth/login.php
index 8e9411464adb5a0e9511c641fe32997ecb12f79b..7150dee5834fa63d8e2a75abe3279c25d11a2e1b 100644
--- a/www/auth/login.php
+++ b/www/auth/login.php
@@ -155,9 +155,7 @@ if (isset($_POST['username'])) {
 			$logger->log(LOG_NOTICE, $session->getTrackID(), 'AUTH', 'ldap', 'OK', $username, $username . ' successfully authenticated');
 			
 			
-			header("Location: " . $relaystate);
-			exit(0);
-
+			SimpleSAML_Utilities::redirect($relaystate);
 		}
 	// ldap_close() om du vil, men frigjoeres naar skriptet slutter
 	}
diff --git a/www/example-simple/saml2-example.php b/www/example-simple/saml2-example.php
index 141cd31c3f01aa2b9eda6dbb8cc0f71941a67b1b..7a1caa6c53047e2cb459fe283430b9c187c804cd 100644
--- a/www/example-simple/saml2-example.php
+++ b/www/example-simple/saml2-example.php
@@ -19,8 +19,11 @@ $session = SimpleSAML_Session::getInstance();
 
 /* Check if valid local session exists.. */
 if (!isset($session) || !$session->isValid() ) {
-	header('Location: /' . $config->getValue('baseurlpath') . 'saml2/sp/initSSO.php?RelayState=' . urlencode(SimpleSAML_Utilities::selfURL()));
-	exit(0);
+	SimpleSAML_Utilities::redirect(
+		'/' . $config->getValue('baseurlpath') .
+		'saml2/sp/initSSO.php',
+		array('RelayState' => SimpleSAML_Utilities::selfURL())
+		);
 }
 
 $attributes = $session->getAttributes();
diff --git a/www/example-simple/shib13-example.php b/www/example-simple/shib13-example.php
index 7ff1810799780b34244e70d28c97299293812262..bdf6fd84457c9d11d722a867307193ebf00b86ba 100644
--- a/www/example-simple/shib13-example.php
+++ b/www/example-simple/shib13-example.php
@@ -15,9 +15,11 @@ $session = SimpleSAML_Session::getInstance();
 
 if (!isset($session) || !$session->isValid() ) {
 	
-	header('Location: /' . $config->getValue('baseurlpath') . 'shib13/sp/initSSO.php?RelayState=' . urlencode(SimpleSAML_Utilities::selfURL()));
-		// . '&idpentityid=' . $idpentityid );
-	exit(0);
+	SimpleSAML_Utilities::redirect(
+		'/' . $config->getValue('baseurlpath') .
+		'shib13/sp/initSSO.php',
+		array('RelayState' => SimpleSAML_Utilities::selfURL())
+		);
 }
 
 $et = new SimpleSAML_XHTML_Template($config, 'status.php');
diff --git a/www/openid/provider/server.php b/www/openid/provider/server.php
index c97a32ad0ddef9aca8659146c23b5cc557d43066..93fa87de0be5442b447538d95b9a0df9363d30ea 100644
--- a/www/openid/provider/server.php
+++ b/www/openid/provider/server.php
@@ -235,9 +235,7 @@ function check_authenticated_user() {
 		$authurl = SimpleSAML_Utilities::addURLparameter('/' . $config->getValue('baseurlpath') . $idpmeta['auth'], 
 			'RelayState=' . urlencode($relaystate));
 		
-	
-		header('Location: ' . $authurl);
-		exit(0);
+		SimpleSAML_Utilities::redirect($authurl);
 	}
 	
 	$attributes = $session->getAttributes();
@@ -333,17 +331,7 @@ function action_sites()
  */
 function redirect_render($redir_url)
 {
-	/*
-    $headers = array(http_found,
-                     header_content_text,
-                     header_connection_close,
-                     'Location: ' . $redir_url,
-                     );
-      */               
-	header('Location: ' . $redir_url);
-                     
-//    $body = sprintf(redirect_message, $redir_url);
- //   return array($headers, $body);
+	SimpleSAML_Utilities::redirect($redir_url);
 }
 
 
diff --git a/www/saml2/idp/SSOService.php b/www/saml2/idp/SSOService.php
index e0c25874ee55d5fdb47cc3111dd310d2cbb985f6..a53d59b4fdf38c2ed6b85ce9dac00ec57622465f 100644
--- a/www/saml2/idp/SSOService.php
+++ b/www/saml2/idp/SSOService.php
@@ -108,16 +108,15 @@ if (isset($_GET['SAMLRequest'])) {
 
 if (!$session->isAuthenticated() ) {
 
-	$relaystate = SimpleSAML_Utilities::selfURLNoQuery() .
-		'?RequestID=' . urlencode($requestid);
-	$authurl = SimpleSAML_Utilities::addURLparameter('/' . $config->getValue('baseurlpath') . $idpmeta['auth'], 
-		'RelayState=' . urlencode($relaystate));
-		
 	$logger->log(LOG_NOTICE, $session->getTrackID(), 'SAML2.0', 'IdP.SSOService', 'AuthNext', $idpmeta['auth'], 
 		'Will go to authentication module ' . $idpmeta['auth']);
-		
-	header('Location: ' . $authurl);
-	exit(0);
+
+	$relaystate = SimpleSAML_Utilities::selfURLNoQuery() .
+		'?RequestID=' . urlencode($requestid);
+	$authurl = '/' . $config->getValue('baseurlpath') . $idpmeta['auth'];
+
+	SimpleSAML_Utilities::redirect($authurl,
+		array('RelayState' => $relaystate));
 } else {
 
 	try {
diff --git a/www/saml2/sp/AssertionConsumerService.php b/www/saml2/sp/AssertionConsumerService.php
index a9dce52a3dbea46044e639408cad5d89a631a529..cc26bb50cc5f7087b441f16492a5c857baf2de5f 100644
--- a/www/saml2/sp/AssertionConsumerService.php
+++ b/www/saml2/sp/AssertionConsumerService.php
@@ -39,8 +39,7 @@ try {
 	
 		$relayState = $authnResponse->getRelayState();
 		if (isset($relayState)) {
-			header("Location: " . $relayState);
-			exit(0);
+			SimpleSAML_Utilities::redirect($relayState);
 		} else {
 			echo 'Could not find RelayState parameter, you are stucked here.';
 		}
diff --git a/www/saml2/sp/SingleLogoutService.php b/www/saml2/sp/SingleLogoutService.php
index dc0f4a977d56703a5ebc017f1667698b6d11859f..0403eaca668b6fa57e45907eec7b494c00db8ba4 100644
--- a/www/saml2/sp/SingleLogoutService.php
+++ b/www/saml2/sp/SingleLogoutService.php
@@ -83,7 +83,7 @@ if (isset($_GET['SAMLRequest'])) {
 	
 
 	if (isset($_GET['RelayState'])) {
-		header('Location: ' . $_GET['RelayState']);
+		SimpleSAML_Utilities::redirect($_GET['RelayState']);
 	} else {
 		
 		echo 'You are now successfully logged out.';
diff --git a/www/saml2/sp/idpdisco.php b/www/saml2/sp/idpdisco.php
index d95629665bb0ac7c2276ac26c1720fb08e6265b5..a87327066b6ed372d0298462e52500fd336cddbb 100644
--- a/www/saml2/sp/idpdisco.php
+++ b/www/saml2/sp/idpdisco.php
@@ -43,8 +43,7 @@ if (isset($_GET['idpentityid'])) {
 	$idpentityid = $_GET['idpentityid'];
 
 	$returnurl = SimpleSAML_Utilities::addURLparameter($return, $returnidparam . '=' . $idpentityid);
-	header('Location: ' . $returnurl);
-	exit(0);
+	SimpleSAML_Utilities::redirect($returnurl);
 }
 
 
diff --git a/www/saml2/sp/initSLO.php b/www/saml2/sp/initSLO.php
index 33e1a178064a2ee0e80a31738e775026a85005f0..4971e55abaa43f4672ebdacb56e8319e5f838a52 100644
--- a/www/saml2/sp/initSLO.php
+++ b/www/saml2/sp/initSLO.php
@@ -67,7 +67,7 @@ if (isset($session) ) {
 	$logger->log(LOG_NOTICE, $session->getTrackID(), 'SAML2.0', 'SP.initSLO', 'AlreadyLoggedOut', 'N/A', 
 		'User is already logged out. Go back to relaystate');
 	
-	header('Location: ' . $relaystate );
+	SimpleSAML_Utilities::redirect($relaystate);
 	
 	#print_r($metadata->getMetaData('sam.feide.no'));
 	#print_r($req);
diff --git a/www/saml2/sp/initSSO.php b/www/saml2/sp/initSSO.php
index ac77f5184e814e0e0d1f0838e75c1a4fc62d852f..20ec003ad5e899c7bd6a6856770edf8a36bb641d 100644
--- a/www/saml2/sp/initSSO.php
+++ b/www/saml2/sp/initSSO.php
@@ -48,9 +48,7 @@ if (!isset($session) || !$session->isValid() ) {
 		$returnURL = urlencode(SimpleSAML_Utilities::selfURL());
 		$discservice = '/' . $config->getValue('baseurlpath') . 'saml2/sp/idpdisco.php?entityID=' . $spentityid . 
 			'&return=' . $returnURL . '&returnIDParam=idpentityid';
-		header('Location: ' . $discservice);
-		exit(0);
-		
+		SimpleSAML_Utilities::redirect($discservice);
 	}
 	
 	
@@ -93,7 +91,7 @@ if (!isset($session) || !$session->isValid() ) {
 		$logger->log(LOG_NOTICE, $session->getTrackID(), 'SAML2.0', 'SP.initSSO', 'AlreadyAuthenticated', '-', 
 			'Go back to RelayState');
 	
-		header('Location: ' . $relaystate );
+		SimpleSAML_Utilities::redirect($relaystate);
 	} else {
 		$et = new SimpleSAML_XHTML_Template($config, 'error.php');
 
diff --git a/www/shib13/idp/SSOService.php b/www/shib13/idp/SSOService.php
index 14ec85a2592f671ecbcf4ca5c9eb446df7a0b813..b032a88e56347fa0b225458eba70d52cd74efca9 100644
--- a/www/shib13/idp/SSOService.php
+++ b/www/shib13/idp/SSOService.php
@@ -100,8 +100,7 @@ if (!$session->isAuthenticated() ) {
 	$relaystate = SimpleSAML_Utilities::selfURLNoQuery() . '?RequestID=' . urlencode($requestid);
 	$authurl = SimpleSAML_Utilities::addURLparameter('/' . $config->getValue('baseurlpath') . $idpmeta['auth'], 
 		'RelayState=' . urlencode($relaystate));
-	header('Location: ' . $authurl);
-	exit(0);
+	SimpleSAML_Utilities::redirect($authurl);
 } else {
 
 	try {
diff --git a/www/shib13/sp/AssertionConsumerService.php b/www/shib13/sp/AssertionConsumerService.php
index 789021d05e247ee999b8432f3d9a3047a29a937d..d9c01baaa71fc3d6deee91a3f8a7d980f7155a0c 100644
--- a/www/shib13/sp/AssertionConsumerService.php
+++ b/www/shib13/sp/AssertionConsumerService.php
@@ -41,8 +41,7 @@ try {
 	if (isset($session)) {
 		$relayState = $authnResponse->getRelayState();
 		if (isset($relayState)) {
-			header("Location: " . $relayState);
-			exit(0);
+			SimpleSAML_Utilities::redirect($relayState);
 		} else {
 			echo 'Could not find RelayState parameter, you are stucked here.';
 		}
diff --git a/www/shib13/sp/idpdisco.php b/www/shib13/sp/idpdisco.php
index f6a2ab454a5ea7bbd1be00db99e5d78a7cac6463..6bbd2eb9d9b408e12e4a0055ef56000a19d71f36 100644
--- a/www/shib13/sp/idpdisco.php
+++ b/www/shib13/sp/idpdisco.php
@@ -39,8 +39,7 @@ if (isset($_GET['idpentityid'])) {
 	$idpentityid = $_GET['idpentityid'];
 
 	$returnurl = SimpleSAML_Utilities::addURLparameter($return, $returnidparam . '=' . $idpentityid);
-	header('Location: ' . $returnurl);
-	exit(0);
+	SimpleSAML_Utilities::redirect($returnurl);
 }
 
 
diff --git a/www/shib13/sp/initSSO.php b/www/shib13/sp/initSSO.php
index d81f5771dac164760a123109d4810c9ee3551cac..90a4b4a3350c10312cc1e5d28979c07edcb79abe 100644
--- a/www/shib13/sp/initSSO.php
+++ b/www/shib13/sp/initSSO.php
@@ -49,8 +49,7 @@ if (!isset($session) || !$session->isValid() ) {
 		$returnURL = urlencode(SimpleSAML_Utilities::selfURL());
 		$discservice = '/' . $config->getValue('baseurlpath') . 'shib13/sp/idpdisco.php?entityID=' . $spentityid . 
 			'&return=' . $returnURL . '&returnIDParam=idpentityid';
-		header('Location: ' . $discservice);
-		exit(0);
+		SimpleSAML_Utilities::redirect($discservice);
 		
 	}
 	
@@ -62,10 +61,7 @@ if (!isset($session) || !$session->isValid() ) {
 			$ar->setRelayState($_GET['RelayState']);
 
 		$url = $ar->createRedirect($idpentityid);
-		header('Location: ' . $url);
-//		echo 'IdP: '  . $idpentityid . ' SP: ' . $spentityid;
-		
-		exit(0);
+		SimpleSAML_Utilities::redirect($url);
 	
 	} catch(Exception $exception) {
 		
@@ -85,7 +81,7 @@ if (!isset($session) || !$session->isValid() ) {
 	$relaystate = $session->getRelayState();
 	
 	if (isset($relaystate) && !empty($relaystate)) {
-		header('Location: ' . $relaystate );
+		SimpleSAML_Utilities::redirect($relaystate);
 	} else {
 		$et = new SimpleSAML_XHTML_Template($config, 'error.php');