Created
January 7, 2018 09:36
-
-
Save Semdevmaster/96e0fe9acc07588494d6adbb833ca57c to your computer and use it in GitHub Desktop.
clear get params in request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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