powerthazan/YOURLS-GA-MP-Tracking

PHP 7, YOURLS 2.0

Opened this issue · 3 comments

Not working with PHP 7.0.
I recieve an error when tried to Activate plugin:

Fatal error: Uncaught Error: Call to undefined function split() in /var/www/ali.onl/user/plugins/ga-measurement-protocol/plugin.php:40 Stack trace: #0 /var/www/ali.onl/user/plugins/ga-measurement-protocol/plugin.php(69): power_ga_mp_gaParseCookie() #1 /var/www/ali.onl/includes/functions-plugins.php(152): power_ga_mp(Array) #2 /var/www/ali.onl/includes/functions-plugins.php(191): yourls_apply_filter('pre_redirect', Array) #3 /var/www/ali.onl/includes/functions.php(684): yourls_do_action('pre_redirect', 'http://ali.onl/...', 302) #4 /var/www/ali.onl/includes/admin/plugins.php(37): yourls_redirect('http://ali.onl/...', 302) #5 /var/www/ali.onl/yourls-loader.php(28): require_once('/var/www/ali.on...') #6 {main} thrown in /var/www/ali.onl/user/plugins/ga-measurement-protocol/plugin.php on line 40

Same error on each link click.

Ubuntu 14.04.5 LTS
Apache/2.4.7
PHP 7.0.9-1+deb.sury.org~trusty+1
YOURLS 2.0

I tried to modify line 40 in plugin.php from
list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4);
to
list($version,$domainDepth, $cid1, $cid2) = explode('[\.]', $_COOKIE["_ga"],4);
All work allright and error is gone. But I don't sure is it right way?

Yes. Your are right.It was happened by PHP 7 Incompatibility.

I do not think this fix is correct. split() uses a (non-perl) regular expression, while explode() uses a constant string. split('[.]') seems to be an elaborate way to simply split on a dot - which makes sense, as a _ga cookie looks like this: GA1.2.1858301290.1402971173

So the line should probably read:
list($version,$domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"],4);