A package to remember a visitor’s original referer
If you want to know how a visitor got on your site you can check the referer request header. Yeah, it’s misspelled . That header contains the url of the previously visited page. Unfortunately browsers will fill that header regardless of the previous url was an internal or external one. So after the first click on an internal link you won’t know anymore on which site a visitor was on previously.
Our new laravel-referer package aims to fix that problem. Once the package is installed it will remember the original referer in session. So even after a users clicks around on your site, you are still able to detect which site he or she visited previously.
Because users are also often tracked using UTM Codes the package will also remember the utm_source query parameter.
The easiest way to retrieve the referer is by just resolving it out of the container:use App\Spatie\Referer\Referer; $referer = app(Referer::class)->get(); // 'google.com'
Or you could opt to use Laravel’s 5.4 fancy new automatic facades:use Facades\Spatie\Referer\Referer; $referer = Referer::get(); // 'google.com'
To know more take a look at the readme of the package on GitHub.
Freek Van der Herten
Freek Van der Herten is a partner and developer at Spatie , an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modernphp and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band .
本文开发（php）相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师
本文标题：A package to remember a visitor’s original referer