Skip to content

Instantly share code, notes, and snippets.

@Semdevmaster
Created January 7, 2018 09:36
Show Gist options
  • Select an option

  • Save Semdevmaster/96e0fe9acc07588494d6adbb833ca57c to your computer and use it in GitHub Desktop.

Select an option

Save Semdevmaster/96e0fe9acc07588494d6adbb833ca57c to your computer and use it in GitHub Desktop.
clear get params in request
<?php
class clearGetParams extends Middlewares\Middleware
{
public $contexts = ['web'];
public function onRequest()
{
if ($gets = request()->query()) {
$white_list = array_fill_keys(explode(',', config('get_params')), null);
if ($diff = array_diff_key($gets, $white_list)) {
unset($gets['q']);
foreach ($diff as $key => $value) {
unset($gets[$key]);
}
$newurl = request()->url() . '/?' . http_build_query($gets);
redirect($newurl, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
}
}
}
}
return 'clearGetParams';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment