CleanTalk - issue with setcookie method

First, happy New Year to everyone!

For the past few months, I have been using CleanTalk antispam as a substitute for Akismet on my ClassicPress sites. I have been very glad with it: it has done the job. However, this week, it has stopped working and made all my CP sites no longer accessible. As soon as I remove CleanTalk from my CP sites, they start working again fine.

Here is an example of the kind of warning I am receiving instead of seeing the frontpage of the website on which I have kept CleanTalk active in order to allow their developers to check the issue (I will remove CleanTalk straight after posting this message):

Warning: setcookie() expects parameter 3 to be int, array given in /home/mayerinf/explorator.info/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 1493

Warning: setcookie() expects parameter 3 to be int, array given in /home/mayerinf/explorator.info/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 1493

Warning: setcookie() expects parameter 3 to be int, array given in /home/mayerinf/explorator.info/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 1493

Warning: setcookie() expects parameter 3 to be int, array given in /home/mayerinf/explorator.info/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 1493

Warning: setcookie() expects parameter 3 to be int, array given in /home/mayerinf/explorator.info/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 1493

I have just received the answer from the CleanTalk developers after they checked. Here is the explanation:

We see that setcookie method works not in accordance with PHP documentation in the ClassicPress. You should check how can you fix this on your side.

I do not know what the “setcookie method” is. But I am wondering if some more technically gifted CP users know how this issue could be solved with a future CP release? (I am a paid CleanTalk user until 2022, but can no longer use them.)

For comparison purposes, I have also CleanTalk installed on one site that uses WP 5: no issue at all.

(One of my CP site is on PHP 7.2, the other ones PHP 7.4, but all have started experiencing the same issue this week.)

3 Likes

Im afraid they are talking b******s :wink:

setcookie() is a PHP core function, nothing to do with CP.

If you look at their code you’ll see whats going on

function apbct_cookie__set($name, $value = '', $expires = 0, $path = '', $domain = null, $secure = false, $httponly = false, $samesite = null ){
	
	// For PHP 7.3+ and above
	if( version_compare( phpversion(), '7.3.0', '>=' ) ){
		
		$params = array(
			'expires'  => $expires,
			'path'     => $path,
			'domain'   => $domain,
			'secure'   => $secure,
			'httponly' => $httponly,
		);
		
		if($samesite)
			$params['samesite'] = $samesite;
		
		setcookie( $name, $value, $params ); // THIS IS LINE 1493
		
	// For PHP 5.6 - 7.2
	}else
		setcookie( $name, $value, $expires, $path, $domain, $secure, $httponly );
}

So the version compare must be returning true and the funtion thinks you are using php 7.3 but its actually 7.2 or lower.

You can only pass the options as an array to setcookie for php 7.3 and above.

Are you 100% sure you are using php 7.3 or above?

6 Likes

Happy New Year!

That’s strange. I’m using CleanTalk (5.132.3) on two sites with php 7.2.25. I haven’t experienced the issue you mention. Are all your sites on the same server?

1 Like

Thank you for your answer.

Yes, I have re-checked, and I can confirm that the site is using PHP 7.4.

Thank you for sharing your experience.

This is interesting. Yes, my sites are on the same server.

I will attempt to remove CleanTalk and reinstall it on one of the sites, and see if it changes something.

Additional information: around the same time, I also got error messages regarding the plugins Guest Author and Feddzy RSS Lite - which I removed.

Try adding this to your child theme functions and tell me what it prints in the footer:

add_action( 'wp_footer', function() {
  var_dump( version_compare( phpversion(), '7.3.0', '>=' ) );
  var_dump( phpversion() );
});
1 Like

Here is the server info for the small site on which I am doing the testing.

serverinfo

I have done as instructed: here is what I can see in the footer:

bool(true) string(5) “7.4.1”

But I am about to reinstall CleanTalk on the website and see what happens.

Well thats odd, so that code should work.

Maybe its a bug in php 7.4? Have you tried switching to 7.3?

1 Like

Unfortunately, as soon as I reinstall it and activate it, the issue occurs again.

Well, as I mentioned, I had one site on PHP 7.2, and the same issue occurred.

And the site that is running WP 5 (on another server though) has CleanTalk working fine, with PHP 7.4 active…

Provided it has nothing to do with CP (and it seems it has nothing to do with it, contrarily to my initial assumptions), two possible answers left:

  1. A problem with hosting.

  2. A conflict with another plugin.

Since I cannot spend hours testing (I have already lost a day with that), I will ask my host if he sees any possible explanation with their configuration, since this might be the most likely explanation.

php 7.2 that block of code should NOT run, it should fall back to the regular setcookie() method.

1 Like

Thank you for your help.

As a subsitute, I have now activated Shield Security on that site. I do not know how far it covers exactly the same field as CleanTalk, but I assume that it will do the job.

Still, I will inquire from my host.

And let’s see if other users with CleanTalk will report similar issues.

This is a strange issue. We definitely haven’t made any changes to setcookie (we couldn’t if we tried, since as @Pross said, it’s a built-in PHP function).

Maybe a bug with your hosting environment? You can tell them something like this: “calling setcookie with an array parameter should work on PHP 7.3 and above, but on my site (running PHP 7.4.1) this generates a warning”

3 Likes

Thank you, James! I have just sent that question to the host, and I will keep you updated.

2 posts were split to a new topic: ClassicPress and PHP 7.4 compatibility

I have just received an answer from the hosting company: this was an issue with the hosting indeed!

Rough translation from French (French original below):

We have been able to reproduce the issue and to identify the cause.

The PHP protection/filtering of our hosting, which is used for preventing abuse of PHP commands by hackers, had not been updated for PHP 7.3 and 7.4. For this reason, the new parameters of some commands were not allowed.

We have corrected it this morning and the issue should not occur again.

Nous avons pu reproduire le problème que vous avez rencontré et avons pu en déterminer la cause.

Le module PHP de protection/filtering de nos hébergements, utilisé contre l’utilisation abusive de commandes PHP par des hackers n’était pas à jour pour les versions PHP 7.3 et 7.4. De ce fait les nouveaux paramètres de certaines commandes n’étaient pas autorisés.

Un correctif a été mis en place ce matin et le problème devrait ne plus apparaître.

I have to go to town now, but I will check that later today. I am confident that it will work properly again now.

Thanks to everybody on the forum for the kind help!

9 Likes

I have now tested it: I confirm that the correction done by the hosting company has solved the issue. Thus it had nothing to do with CP or with CleanTalk!

6 Likes

who is the host? just curious