1 <?php
2 3 4 5 6
7 class Cookie {
8 static $report_errors = true;
9
10 11 12 13 14 15 16 17 18 19 20
21 static function set($name, $value, $expiryDays = 90, $path = null, $domain = null, $secure = false, $httpOnly = false) {
22 if(!headers_sent($file, $line)) {
23 $expiry = $expiryDays > 0 ? time()+(86400*$expiryDays) : 0;
24 $path = ($path) ? $path : Director::baseURL();
25
26
27 if(version_compare(phpversion(), 5.2, '<')) {
28 setcookie($name, $value, $expiry, $path, $domain, $secure);
29 } else {
30 setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
31 }
32 } else {
33 if(self::$report_errors) user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
34 }
35 }
36
37 38 39
40 static function get($name) {
41 return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null;
42 }
43
44 static function forceExpiry( $name ) {
45 if(!headers_sent($file, $line)) {
46 setcookie( $name, null, time() - 86400 );
47 }
48 }
49
50 static function set_report_errors($reportErrors) {
51 self::$report_errors = $reportErrors;
52 }
53 static function report_errors() {
54 return self::$report_errors;
55 }
56 }
57
58 ?>
59
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-