From 6bf91cba556c0872074b32e9d72cae973724fe8b Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Fri, 2 Mar 2007 13:09:01 +0000 Subject: [PATCH] bug #1672379 Call to undefined function PMA_removeCookie() --- ChangeLog | 3 + libraries/common.lib.php | 142 +++++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9283a44b6..c38e24d2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - ChangeLog $Id$ $HeadURL$ +2007-03-02 Sebastian Mendel + * libraries/common.lib.php: bug #1672379 Call to undefined function PMA_removeCookie() + 2007-03-01 Sebastian Mendel * libraries/common.lib.php: bug #1671813 CVE-2006-1549 deep recursion crash diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 5f218c887..34b637e0f 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -433,6 +433,77 @@ function PMA_getenv($var_name) { return ''; } +/** + * removes cookie + * + * @uses PMA_Config::isHttps() + * @uses PMA_Config::getCookiePath() + * @uses setcookie() + * @uses time() + * @param string $cookie name of cookie to remove + * @return boolean result of setcookie() + */ +function PMA_removeCookie($cookie) +{ + return setcookie($cookie, '', time() - 3600, + PMA_Config::getCookiePath(), '', PMA_Config::isHttps()); +} + +/** + * sets cookie if value is different from current cokkie value, + * or removes if value is equal to default + * + * @uses PMA_Config::isHttps() + * @uses PMA_Config::getCookiePath() + * @uses $_COOKIE + * @uses PMA_removeCookie() + * @uses setcookie() + * @uses time() + * @param string $cookie name of cookie to remove + * @param mixed $value new cookie value + * @param string $default default value + * @param int $validity validity of cookie in seconds (default is one month) + * @param bool $httponlt whether cookie is only for HTTP (and not for scripts) + * @return boolean result of setcookie() + */ +function PMA_setCookie($cookie, $value, $default = null, $validity = null, $httponly = true) +{ + if ($validity == null) { + $validity = 2592000; + } + if (strlen($value) && null !== $default && $value === $default + && isset($_COOKIE[$cookie])) { + // remove cookie, default value is used + return PMA_removeCookie($cookie); + } + + if (! strlen($value) && isset($_COOKIE[$cookie])) { + // remove cookie, value is empty + return PMA_removeCookie($cookie); + } + + if (! isset($_COOKIE[$cookie]) || $_COOKIE[$cookie] !== $value) { + // set cookie with new value + /* Calculate cookie validity */ + if ($validity == 0) { + $v = 0; + } else { + $v = time() + $validity; + } + /* Use native support for httponly cookies if available */ + if (version_compare(PHP_VERSION, '5.2.0', 'ge')) { + return setcookie($cookie, $value, $v, + PMA_Config::getCookiePath(), '', PMA_Config::isHttps(), $httponly); + } else { + return setcookie($cookie, $value, $v, + PMA_Config::getCookiePath() . ($httponly ? '; HttpOnly' : ''), '', PMA_Config::isHttps()); + } + } + + // cookie has already $value as value + return true; +} + /** * include here only libraries which contain only function definitions * no code in main()! @@ -2543,77 +2614,6 @@ if (typeof(window.parent) != 'undefined' .htmlspecialchars($database) . ''; } - /** - * removes cookie - * - * @uses PMA_Config::isHttps() - * @uses PMA_Config::getCookiePath() - * @uses setcookie() - * @uses time() - * @param string $cookie name of cookie to remove - * @return boolean result of setcookie() - */ - function PMA_removeCookie($cookie) - { - return setcookie($cookie, '', time() - 3600, - PMA_Config::getCookiePath(), '', PMA_Config::isHttps()); - } - - /** - * sets cookie if value is different from current cokkie value, - * or removes if value is equal to default - * - * @uses PMA_Config::isHttps() - * @uses PMA_Config::getCookiePath() - * @uses $_COOKIE - * @uses PMA_removeCookie() - * @uses setcookie() - * @uses time() - * @param string $cookie name of cookie to remove - * @param mixed $value new cookie value - * @param string $default default value - * @param int $validity validity of cookie in seconds (default is one month) - * @param bool $httponlt whether cookie is only for HTTP (and not for scripts) - * @return boolean result of setcookie() - */ - function PMA_setCookie($cookie, $value, $default = null, $validity = null, $httponly = true) - { - if ($validity == null) { - $validity = 2592000; - } - if (strlen($value) && null !== $default && $value === $default - && isset($_COOKIE[$cookie])) { - // remove cookie, default value is used - return PMA_removeCookie($cookie); - } - - if (! strlen($value) && isset($_COOKIE[$cookie])) { - // remove cookie, value is empty - return PMA_removeCookie($cookie); - } - - if (! isset($_COOKIE[$cookie]) || $_COOKIE[$cookie] !== $value) { - // set cookie with new value - /* Calculate cookie validity */ - if ($validity == 0) { - $v = 0; - } else { - $v = time() + $validity; - } - /* Use native support for httponly cookies if available */ - if (version_compare(PHP_VERSION, '5.2.0', 'ge')) { - return setcookie($cookie, $value, $v, - PMA_Config::getCookiePath(), '', PMA_Config::isHttps(), $httponly); - } else { - return setcookie($cookie, $value, $v, - PMA_Config::getCookiePath() . ($httponly ? '; HttpOnly' : ''), '', PMA_Config::isHttps()); - } - } - - // cookie has already $value as value - return true; - } - /** * Displays a lightbulb hint explaining a known external bug * that affects a functionality