Make language setting cookie a permanent cookie
Make language setting cookie a permanent cookie

While I know that you can set cookies up to the year 2038, I would
prefer to be a good citizen to the user's browser, so I'm capping
the lifetime at 1 year.

Bug #67

--- a/include/Resource.class.php
+++ b/include/Resource.class.php
@@ -16,6 +16,11 @@
  * Constant of the locale cookie in the user's browser
  */
 define('GITPHP_LOCALE_COOKIE', 'GitPHPLocale');
+
+/**
+ * Locale cookie lifetime
+ */
+define('GITPHP_LOCALE_COOKIE_LIFETIME', 60*60*24*365);		// 1 year
 
 /**
  * Resource factory class

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -66,7 +66,7 @@
 		$httpAcceptLang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
 		$preferredLocale = GitPHP_Resource::FindPreferredLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']);
 		if (!empty($preferredLocale)) {
-			setcookie(GITPHP_LOCALE_COOKIE, $preferredLocale);
+			setcookie(GITPHP_LOCALE_COOKIE, $preferredLocale, time()+GITPHP_LOCALE_COOKIE_LIFETIME);
 			GitPHP_Resource::Instantiate($preferredLocale);
 		}
 	}
@@ -75,7 +75,7 @@
 		/*
 		 * Create a dummy cookie to prevent browser delay
 		 */
-		setcookie(GITPHP_LOCALE_COOKIE, 0);
+		setcookie(GITPHP_LOCALE_COOKIE, 0, time()+GITPHP_LOCALE_COOKIE_LIFETIME);
 	}
 
 } else if (isset($_GET['l']) && !empty($_GET['l'])) {
@@ -83,7 +83,7 @@
 	/*
 	 * User picked something
 	 */
-	setcookie(GITPHP_LOCALE_COOKIE, $_GET['l']);
+	setcookie(GITPHP_LOCALE_COOKIE, $_GET['l'], time()+GITPHP_LOCALE_COOKIE_LIFETIME);
 	GitPHP_Resource::Instantiate($_GET['l']);
 
 } else if (isset($_COOKIE[GITPHP_LOCALE_COOKIE]) && !empty($_COOKIE[GITPHP_LOCALE_COOKIE])) {

comments