Add WebResponse::clearCookie()
authorGergő Tisza <tgr.huwiki@gmail.com>
Tue, 3 Nov 2015 08:45:41 +0000 (00:45 -0800)
committerAnomie <bjorsch@wikimedia.org>
Tue, 3 Nov 2015 20:14:33 +0000 (20:14 +0000)
Easier-to-read alias for setCookie(..., '', time() - 86400).

Change-Id: I0357c4a38085c4754bf6ff7e40756179d19b912d

includes/WebResponse.php

index bb7682d..26fb20f 100644 (file)
@@ -136,6 +136,19 @@ class WebResponse {
                                $options['httpOnly'] );
                }
        }
+
+       /**
+        * Unset a browser cookie.
+        * This sets the cookie with an empty value and an expiry set to a time in the past,
+        * which will cause the browser to remove any cookie with the given name, domain and
+        * path from its cookie store. Options other than these (and prefix) have no effect.
+        * @param string $name Cookie name
+        * @param array $options Cookie options, see {@link setCookie()}
+        * @since 1.27
+        */
+       public function clearCookie( $name, $options = array() ) {
+               $this->setCookie( $name, '', time() - 31536000 /* 1 year */, $options );
+       }
 }
 
 /**