Skip to content

Instantly share code, notes, and snippets.

@carestad
Last active February 21, 2023 20:49
Show Gist options
  • Save carestad/b4b59cdb6c82cb3229f4908c3c8372e9 to your computer and use it in GitHub Desktop.
Save carestad/b4b59cdb6c82cb3229f4908c3c8372e9 to your computer and use it in GitHub Desktop.
Laravel superglobals cheat sheet
<?php
$_SERVER['HTTP_HOST'] = Request::getHttpHost();
$_SERVER['HTTP_HOST'] = request()->getHttpHost();
// Alternative could be to use URL::previous(), but this will always return current URL if no referer is present.
// @see https://github.com/laravel/framework/blob/5.7/src/Illuminate/Routing/UrlGenerator.php#L154
$_SERVER['HTTP_REFERER'] = Request::header('referer', 'default');
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = Request::getPreferredLanguage();
$_SERVER['HTTP_USER_AGENT'] = Request::userAgent();
$_SERVER['REQUEST_URI'] = Request::getRequestUri();
$_SERVER['REQUEST_URI'] = request()->getRequestUri();
$_SERVER['SERVER_NAME'] = Request::server('SERVER_NAME');
$_GET['foo'] = Request::query('foo');
$_POST['foo'] = Request::input('foo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment