Subversion Repositories oidplus

Rev

Rev 564 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  22. class OIDplusCookieUtils {
  23.  
  24.         public function unsetcookie($name) {
  25.                 $this->setcookie($name, '', time()-9999, true);
  26.         }
  27.  
  28.         public function setcookie($name, $value, $expires=0, $allowJS=false) {
  29.                 // $path = ini_get('session.cookie_path');
  30.                 $path = OIDplus::webpath(null,true);
  31.                 if (empty($path)) $path = '/';
  32.  
  33.                 $domain = '';
  34.                 $secure = false;
  35.                 $httponly = !$allowJS;
  36.                 $samesite = OIDplus::baseConfig()->getValue('COOKIE_SAMESITE_POLICY', 'Strict');
  37.  
  38.                 if (strnatcmp(phpversion(),'7.3.0') >= 0) {
  39.                         $options = array(
  40.                                 "expires" => $expires,
  41.                                 "path" => $path,
  42.                                 "domain" => $domain,
  43.                                 "secure" => $secure,
  44.                                 "httponly" => $httponly,
  45.                                 "samesite" => $samesite
  46.                         );
  47.                         setcookie($name, $value, $options);
  48.                 } else {
  49.                         setcookie($name, $value, $expires, $path.'; samesite='.$samesite, $domain, $secure, $httponly);
  50.                 }
  51.         }
  52.  
  53. }
  54.  
  55.