Commits

Anonymous committed 1a049dc

Bugfix in foreach-loop ('name' must be last, as it also is the array's name); consistent handling for 'cookie_secure' config item

Comments (0)

Files changed (1)

system/core/Input.php

 	* @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]))
 				{
 		{
 			$path = config_item('cookie_path');
 		}
+		if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
+		{
+			$secure = config_item('cookie_secure');
+		}
 
 		if ( ! is_numeric($expire))
 		{
 			$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);
 	}