Skip to content

Commit 18c8a28

Browse files
author
davydovct
committed
Add cookie set to helper
1 parent 209e9c3 commit 18c8a28

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

cleantalk.antispam/lib/Cleantalk/Antispam/SFW.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
use Cleantalk\Common\Helper as CleantalkHelper;
66
use Cleantalk\Common\API as CleantalkAPI;
77

8-
/*
9-
* CleanTalk SpamFireWall base class
10-
* author Cleantalk team (welcome@cleantalk.org)
11-
* copyright (C) 2014 CleanTalk team (http://cleantalk.org)
12-
* license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
13-
* see https://github.com/CleanTalk/php-antispam
14-
*/
15-
8+
/**
9+
* CleanTalk SpamFireWall base class.
10+
* Compatible with any CMS.
11+
*
12+
* @package CleanTalk SFW functions
13+
* @subpackage SFW
14+
* @version 1.0
15+
* @author Cleantalk team (welcome@cleantalk.org)
16+
* @copyright (C) 2014 CleanTalk team (https://cleantalk.org)
17+
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
18+
* @see https://github.com/CleanTalk/php-antispam
19+
*/
1620
abstract class SFW
1721
{
1822
private $api_key = '';

cleantalk.antispam/lib/Cleantalk/Common/Helper.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,37 @@ static function apache_request_headers(){
661661
return $headers;
662662
}
663663

664-
/*
664+
/**
665665
* Check if api key is correct
666666
* @return bool
667667
*/
668668
static function api_key__is_correct($api_key) {
669669
return $api_key && preg_match('/^[a-z\d]{3,15}$/', $api_key) ? true : false;
670-
}
670+
}
671+
672+
/**
673+
* Setting cookie
674+
*/
675+
static function cookie__set($name, $value = '', $expires = 0, $path = '', $domain = null, $secure = false, $httponly = false, $samesite = null ){
676+
677+
// For PHP 7.3+ and above
678+
if( version_compare( phpversion(), '7.3.0', '>=' ) ){
679+
680+
$params = array(
681+
'expires' => $expires,
682+
'path' => $path,
683+
'domain' => $domain,
684+
'secure' => $secure,
685+
'httponly' => $httponly,
686+
);
687+
688+
if($samesite)
689+
$params['samesite'] = $samesite;
690+
691+
setcookie( $name, $value, $params );
692+
693+
// For PHP 5.6 - 7.2
694+
}else
695+
setcookie( $name, $value, $expires, $path, $domain, $secure, $httponly );
696+
}
671697
}

0 commit comments

Comments
 (0)