本文整理汇总了PHP中Illuminate\Http\Request::getHttpHost方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getHttpHost方法的具体用法?PHP Request::getHttpHost怎么用?PHP Request::getHttpHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::getHttpHost方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$pipe = $request->pipe;
if ($pipe) {
$finalServer = $this->resolver->resolve($pipe);
if ($finalServer != $request->getHttpHost()) {
return redirect(str_replace($request->getHttpHost(), $finalServer, $request->getUri()), 307);
}
}
return $next($request);
}
示例2: authLogin
/**
* @param Request $request
* @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View|\Symfony\Component\HttpFoundation\Response
*/
public function authLogin(Request $request)
{
$authService = new authService();
$host = explode('.', $request->getHttpHost());
$role = $host[0];
$email = $request->input('email', false);
$password = $request->input('password', false);
$postAjax = $request->ajax();
try {
$results = $authService->login($email, $password, $role);
if (!$postAjax) {
if ($results['ok']) {
return redirect()->intended('/');
} else {
return view('auth.login', $results);
}
} else {
return response()->json($results);
}
} catch (\Exception $e) {
// @codeCoverageIgnoreStart
$return['error'] = $e->getMessage();
// @codeCoverageIgnoreEnd
}
return view('auth.login');
}
示例3: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$host = preg_replace('"^\\w+://(www\\.)?"i', '', \Config::get('app.url'));
$test = str_replace($host, '', $request->getHttpHost());
preg_match("'^([^\\.]+)\\.\$'", $test, $m);
static::subdomen(@$m[1]);
return $next($request);
}
示例4: handle
/**
* This middleware forces the entire application to use SSL. We like that, because it's secure.
*
* Shamelessly copied from: http://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$force = env('FORCE_DOMAIN', null);
if ($force != null && $request->getHttpHost() != $force) {
return redirect()->to(env('APP_URL') . '/' . ($request->path() == '/' ? '' : $request->path()));
}
return $next($request);
}
示例5: handle
/**
* Handle an incoming request.
*
* The following filter simply retrieves the current account based on the request information
* and then sets this value for future retrieval. If no account can be found for the request,
* then two things need to happen:
*
* 1. Check to see if ANY accounts have been configured if no accounts exist then
* 2. Ask the user if they'd like to setup the default (first) account. This is required
* for new installations.
* 3. If an account does exist but does not match the domain, then we throw an account
* not found exception and deal with that later.
*
* @throws AccountNotFoundException
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$account = CurrentAccount::determine($request->getHttpHost());
if (!$account) {
$count = $this->accountService->totalNumberOfAccounts();
if ($count === 0) {
return redirect()->route('install');
}
throw new AccountNotFoundException();
}
CurrentAccount::set($account);
return $next($request);
}
示例6: resolve
/**
* Resolve locale using domain name
*
* @return mixed
*/
public function resolve()
{
$httpHost = $this->request->getHttpHost();
$domains = explode('.', $httpHost);
$level = config('localizer.domain.level', 3);
return ($total = count($domains)) >= $level ? $domains[$total - $level] : null;
}
示例7: localizedURL
/**
* Returns an URL adapted to locale
*
* @param string $locale
* @return string
*/
private function localizedURL($locale)
{
// Default language doesn't get a special subdomain
$locale = $locale !== $this->defaultLocale ? strtolower($locale) . '.' : '';
// URL elements
$uri = $this->request->getRequestUri();
$scheme = $this->request->getScheme();
// Get host
$array = explode('.', $this->request->getHttpHost());
$host = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1];
// Create URL from template
$url = str_replace(['[scheme]', '[locale]', '[host]', '[uri]'], [$scheme, $locale, $host, $uri], $this->config['locale_url']);
return url($url);
}
示例8: setRequestData
public function setRequestData(\App\Action $action, \Illuminate\Http\Request $request)
{
if (!$action->app) {
$action->app = $request->getHttpHost();
}
if (!$action->http_referrer_raw) {
$action->http_referrer_raw = $request->header('Referer');
}
if (!$action->user_agent_raw) {
$action->user_agent_raw = $request->header('User-Agent');
}
if (!$action->ip) {
// TODO make sure this accounts for CDNs/proxies
$action->ip = $request->ip();
}
// TODO location
}
示例9: getLocalizedURL
/**
* Returns an URL adapted to $locale
*
* @throws SupportedLocalesNotDefined
* @throws UnsupportedLocaleException
*
* @param string|boolean $locale Locale to adapt, false to remove locale
* @param string|false $url URL to adapt in the current language. If not passed, the current url would be
* taken.
* @param array $attributes Attributes to add to the route, if empty, the system would try to extract
* them from the url.
*
*
* @return string|false URL translated, False if url does not exist
*/
public function getLocalizedURL($locale = null, $url = null, $attributes = [])
{
// Use default if not set
if ($locale === null) {
$locale = $this->getCurrentLocale();
}
// Get request Uri
if (empty($url)) {
$url = $this->request->getRequestUri();
} else {
$parts = parse_url($url);
$url = $parts['path'] . (isset($parts['query']) ? '?' . $parts['query'] : '');
}
$scheme = $this->request->getScheme();
$locale = $locale && $locale !== $this->getDefaultLocale() ? "{$locale}." : '';
// Get host
$array = explode('.', $this->request->getHttpHost());
$host = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1];
return app('url')->to("{$scheme}://{$locale}{$host}{$url}", $attributes);
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
} else {
$host = explode('.', $request->getHttpHost());
$role = $host[0];
$user = $this->auth->user();
if ($role == KACANA_USER_ROLE_ADMIN && $user->role == KACANA_USER_ROLE_ADMIN || $role == KACANA_USER_ROLE_PARTNER && $user->role == KACANA_USER_ROLE_PARTNER || $role != KACANA_USER_ROLE_PARTNER && $role != KACANA_USER_ROLE_ADMIN) {
return $next($request);
} else {
\Auth::logout();
return redirect()->to('auth/login')->with('__error_code_login_one_check__', KACANA_AUTH_LOGIN_ERROR_NOT_PERMISSION);
}
}
}
示例11: signup
/**
* @param Request $request
* @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View|\Symfony\Component\HttpFoundation\Response
*/
public function signup(Request $request)
{
$authService = new authService();
$emailService = new mailService();
$name = $request->input('name', '');
$email = $request->input('email', '');
$phone = $request->input('phone', '');
$password = $request->input('password', '');
$confirmPassword = $request->input('confirmPassword', '');
$postAjax = $request->ajax();
$host = explode('.', $request->getHttpHost());
$roleLink = $host[0];
try {
if ($request->isMethod('post')) {
$results = $authService->signup($name, $email, $phone, $password, $confirmPassword);
if ($results['ok']) {
$user = $results['data'];
if ($roleLink != KACANA_AUTH_ADMIN_NAME) {
\Auth::loginUsingId($user->id, true);
}
$emailService->sendEmailNewUser($email);
}
if ($postAjax) {
return response()->json($results);
} else {
if ($results['ok']) {
return redirect()->intended('/');
} else {
return view('auth.signup', $results);
}
}
}
} catch (\Exception $e) {
// @codeCoverageIgnoreStart
$return['error'] = $e->getMessage();
// @codeCoverageIgnoreEnd
}
return view('auth.signup');
}
示例12: getHttpHost
/**
* Returns the HTTP host being requested.
*
* The port name will be appended to the host if it's non-standard.
*
* @return string
* @static
*/
public static function getHttpHost()
{
//Method inherited from \Symfony\Component\HttpFoundation\Request
return \Illuminate\Http\Request::getHttpHost();
}
示例13: getTld
/**
* Get top level domain.
*
* @return string
*/
public function getTld()
{
return substr(strrchr($this->request->getHttpHost(), '.'), 0);
}