Bugfix in foreach-loop ('name' must be last, as it also is the array's name); consistent handling for 'cookie_secure' config item
diff --git a/system/core/Input.php b/system/core/Input.php
index 25fe102..6262453 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -211,11 +211,12 @@
 	* @param	bool	true makes the cookie secure
 	* @return	void
 	*/
-	function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL)
+	function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
 	{
 		if (is_array($name))
 		{
-			foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name', 'secure') as $item)
+			// always leave 'name' in last place, as the loop will break otherwise, due to $$item
+			foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item)
 			{
 				if (isset($name[$item]))
 				{
@@ -236,6 +237,10 @@
 		{
 			$path = config_item('cookie_path');
 		}
+		if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
+		{
+			$secure = config_item('cookie_secure');
+		}
 
 		if ( ! is_numeric($expire))
 		{
@@ -246,12 +251,6 @@
 			$expire = ($expire > 0) ? time() + $expire : 0;
 		}
 
-		// If TRUE/FALSE is not provided, use the config
-		if ( ! is_bool($secure))
-		{
-			$secure = (bool) (config_item('cookie_secure') === TRUE);
-		}
-
 		setcookie($prefix.$name, $value, $expire, $path, $domain, $secure);
 	}