Changeset 479 for trunk/lib/App.inc.php
- Timestamp:
- May 3, 2014 11:09:03 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/App.inc.php
r478 r479 180 180 $this->timer->start('_app'); 181 181 182 183 184 185 186 182 // The codebase now requires a minimum PHP version. 183 $codebase_minimum_php_version = '5.3.0'; 184 if (version_compare(PHP_VERSION, $codebase_minimum_php_version, '<')) { 185 $this->logMsg(sprintf('Codebase minimum PHP version of %s not satisfied (you have %s). ', $codebase_minimum_php_version, phpversion()), LOG_NOTICE, __FILE__, __LINE__); 186 } 187 187 } 188 188 … … 615 615 $message = strip_tags(preg_replace('/\s+/', ' ', $message), (!empty($strip_tags_allow[1]) ? join('> ', $strip_tags_allow[1]) . '>' : null)); 616 616 617 618 617 // Serialize multi-line messages. 618 $message = preg_replace('/\s+/m', ' ', $message); 619 619 620 620 // Store this event under a unique key, counting each time it occurs so that it only gets reported a limited number of times. … … 1261 1261 } 1262 1262 1263 1264 1265 1266 1267 * @param string $nameThe name of the cookie.1268 * @param string $valueThe value of the cookie.1269 * @param string $expireThe time the cookie expires, as a unix timestamp or string value passed to strtotime.1270 * @param string $pathThe path on the server in which the cookie will be available on1271 * @param string $domainThe domain that the cookie is available to1272 * @param bool $secureIndicates that the cookie should only be transmitted over a secure HTTPS connection from the client.1273 * @param bool $httponlyWhen TRUE the cookie will be made accessible only through the HTTP protocol (makes cookies unreadable to javascript).1274 * @return boolTrue on success, false on error.1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1263 /* 1264 * Sets a cookie, with error checking and some sane defaults. 1265 * 1266 * @access public 1267 * @param string $name The name of the cookie. 1268 * @param string $value The value of the cookie. 1269 * @param string $expire The time the cookie expires, as a unix timestamp or string value passed to strtotime. 1270 * @param string $path The path on the server in which the cookie will be available on 1271 * @param string $domain The domain that the cookie is available to 1272 * @param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. 1273 * @param bool $httponly When TRUE the cookie will be made accessible only through the HTTP protocol (makes cookies unreadable to javascript). 1274 * @return bool True on success, false on error. 1275 * @author Quinn Comendant <quinn@strangecode.com> 1276 * @version 1.0 1277 * @since 02 May 2014 16:36:34 1278 */ 1279 public function setCookie($name, $value, $expire='+10 years', $path=null, $domain=null, $secure=null, $httponly=null) 1280 { 1281 if (!is_scalar($name)) { 1282 $this->logMsg(sprintf('Cookie name must be scalar, is not: %s', getDump($name)), LOG_NOTICE, __FILE__, __LINE__); 1283 return false; 1284 } 1285 if (!is_scalar($value)) { 1286 $this->logMsg(sprintf('Cookie "%s" value must be scalar, is not: %s', $name, getDump($value)), LOG_NOTICE, __FILE__, __LINE__); 1287 return false; 1288 } 1289 1290 // Defaults. 1291 $expire = (is_numeric($expire) ? $expire : (is_string($expire) ? strtotime($expire) : $expire)); 1292 $secure = $secure ?: ('' != getenv('HTTPS') && $this->getParam('ssl_enabled')); 1293 $httponly = $httponly ?: true; 1294 1295 // Make sure the expiration date is a valid 32bit integer. 1296 if (is_int($expire) && $expire > 2147483647) { 1297 $this->logMsg(sprintf('Cookie "%s" expire time exceeds a 32bit integer (%s)', $key, date('r', $expire)), LOG_NOTICE, __FILE__, __LINE__); 1298 } 1299 1300 // Measure total cookie length and warn if larger than max recommended size of 4093. 1301 // https://stackoverflow.com/questions/640938/what-is-the-maximum-size-of-a-web-browsers-cookies-key 1302 // The date the header name include 51 bytes: Set-Cookie: ; expires=Fri, 03-May-2024 00:04:47 GMT 1303 $cookielen = strlen($name . $value . $path . $domain . ($secure ? '; secure' : '') . ($httponly ? '; httponly' : '')) + 51; 1304 if ($cookielen > 4093) { 1305 $this->logMsg(sprintf('Cookie "%s" has a size greater than 4093 bytes (is %s bytes)', $key, $cookielen), LOG_NOTICE, __FILE__, __LINE__); 1306 } 1307 1308 // Ensure PHP version allow use of httponly. 1309 if (version_compare(PHP_VERSION, '5.2.0', '>=')) { 1310 $ret = setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); 1311 } else { 1312 $ret = setcookie($name, $value, $expire, $path, $domain, $secure); 1313 } 1314 1315 if (false === $ret) { 1316 $this->logMsg(sprintf('Failed to set cookie (%s=%s) probably due to output before headers.', $name, $value), LOG_NOTICE, __FILE__, __LINE__); 1317 } 1318 return $ret; 1319 } 1320 1320 } // End.
Note: See TracChangeset
for help on using the changeset viewer.