Rev 580 | Rev 799 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
557 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
730 | daniel-mar | 22 | class OIDplusCookieUtils extends OIDplusBaseClass { |
557 | daniel-mar | 23 | |
24 | public function unsetcookie($name) { |
||
25 | $this->setcookie($name, '', time()-9999, true); |
||
26 | } |
||
27 | |||
564 | daniel-mar | 28 | public function setcookie($name, $value, $expires=0, $allowJS=false, $samesite=null) { |
557 | daniel-mar | 29 | // $path = ini_get('session.cookie_path'); |
30 | $path = OIDplus::webpath(null,true); |
||
31 | if (empty($path)) $path = '/'; |
||
32 | |||
33 | $domain = ''; |
||
580 | daniel-mar | 34 | $secure = OIDplus::isSSL(); |
557 | daniel-mar | 35 | $httponly = !$allowJS; |
564 | daniel-mar | 36 | if (is_null($samesite)) { |
37 | $samesite = OIDplus::baseConfig()->getValue('COOKIE_SAMESITE_POLICY', 'Strict'); |
||
38 | } |
||
557 | daniel-mar | 39 | |
40 | if (strnatcmp(phpversion(),'7.3.0') >= 0) { |
||
41 | $options = array( |
||
42 | "expires" => $expires, |
||
43 | "path" => $path, |
||
44 | "domain" => $domain, |
||
45 | "secure" => $secure, |
||
46 | "httponly" => $httponly, |
||
47 | "samesite" => $samesite |
||
48 | ); |
||
49 | setcookie($name, $value, $options); |
||
50 | } else { |
||
51 | setcookie($name, $value, $expires, $path.'; samesite='.$samesite, $domain, $secure, $httponly); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | } |
||
56 |