* It also has some session register functions that work across various
* php versions.
*
- * @copyright 1999-2012 The SquirrelMail Project Team
+ * @copyright 1999-2020 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
function sqsetcookie($sName, $sValue='deleted', $iExpire=0, $sPath="", $sDomain="",
$bSecure=false, $bHttpOnly=true, $bReplace=false) {
+ // some environments can get overwhelmed by an excessive
+ // setting of the same cookie over and over (e.g., many
+ // calls to this function via sqsession_is_active() result
+ // in repeated setting of the session cookie when $bReplace
+ // is FALSE, but something odd happens (during login only)
+ // if we change that to default TRUE) ... so we keep our own
+ // naive per-request name/value cache and only set the cookie
+ // if its value is changing (or never seen before)
+ static $cookies = array();
+ if (isset($cookies[$sName]) && $cookies[$sName] === $sValue)
+ return;
+ else
+ $cookies[$sName] = $sValue;
+
+
// if we have a secure connection then limit the cookies to https only.
global $is_secure_connection;
if ($sName && $is_secure_connection)
* @return string The path, filename and any arguments for the
* current script
*/
-function php_self() {
+function php_self($with_query_string=TRUE) {
- $request_uri = '';
+ static $request_uri = '';
+ if (!empty($request_uri))
+ return ($with_query_string ? $request_uri : (strpos($request_uri, '?') !== FALSE ? substr($request_uri, 0, strpos($request_uri, '?')) : $request_uri));
// first try $_SERVER['PHP_SELF'], which seems most reliable
// (albeit it usually won't include the query string)
$request_uri .= '?' . $query_string;
}
- return $request_uri;
+ global $php_self_pattern, $php_self_replacement;
+ if (!empty($php_self_pattern))
+ $request_uri = preg_replace($php_self_pattern, $php_self_replacement, $request_uri);
+ return ($with_query_string ? $request_uri : (strpos($request_uri, '?') !== FALSE ? substr($request_uri, 0, strpos($request_uri, '?')) : $request_uri));
}
/**
- * Sanitize a value using htmlspecialchars() or similar, but also
- * recursively run htmlspecialchars() (or similar) on array keys
+ * Sanitize a value using sm_encode_html_special_chars() or similar, but also
+ * recursively run sm_encode_html_special_chars() (or similar) on array keys
* and values.
*
* If $value is not a string or an array with strings in it,
if ($quote_style === TRUE)
return str_replace(array('\'', '"'), array(''', '"'), $value);
else
- return htmlspecialchars($value, $quote_style);
+ return sm_encode_html_special_chars($value, $quote_style);
}
// anything else gets returned with no changes