Skip to content

Commit

Permalink
Switch utf8_encode to mb_convert_encoding
Browse files Browse the repository at this point in the history
`utf8_encode()` is not included by default with PHP 7 now. Since
Laravel requires the MB extension, it’s safe to switch over to
`mb_convert_encoding()`
  • Loading branch information
DougSisk committed Nov 12, 2016
1 parent 30e4eb7 commit bf6259a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"require": {
"php": ">=5.4.0",
"ext-mbstring": "*",
"illuminate/http": "^5.0",
"piwik/referrer-spam-blacklist": "@dev"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/BlockReferralSpam.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class BlockReferralSpam
*/
public function handle($request, Closure $next)
{
$referer = utf8_encode($request->headers->get('referer'));
$referer = mb_convert_encoding($request->headers->get('referer'), 'UTF-8');
$spammerList = config('app.referral_spam_list_location', base_path('vendor/piwik/referrer-spam-blacklist/spammers.txt'));

// Make sure there's a referrer
if (!empty($referer) && file_exists($spammerList)) {
$blockedHosts = file($spammerList, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

foreach ($blockedHosts as $i => $host) {
$blockedHosts[$i] = trim(utf8_encode($host));
$blockedHosts[$i] = trim(mb_convert_encoding($host, 'UTF-8'));
}

preg_match('/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/', $referer, $matches);
Expand Down

0 comments on commit bf6259a

Please sign in to comment.