本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::isSecure方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isSecure方法的具体用法?PHP Request::isSecure怎么用?PHP Request::isSecure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::isSecure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromRequest
public function fromRequest(Request $request)
{
$this->setBaseUrl($request->getBaseUrl());
$this->setMethod($request->getMethod());
$this->setHost($request->getHost());
$this->setScheme($request->getScheme());
$this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
$this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
}
示例2: getPath
/**
* {@inheritDoc}
*/
public function getPath($relativePath, $isFlushable)
{
$container = $this->container;
$object = $container->get_object($relativePath);
if ($this->request && $this->request->isSecure()) {
return $object->public_ssl_uri();
} else {
return $object->public_uri();
}
}
示例3: fromRequest
/**
* Updates the RequestContext info based on a HttpFoundation Request.
*
* @param Request $request A Request instance
*/
public function fromRequest(Request $request)
{
$this->setBaseUrl($request->getBaseUrl());
$this->setPathInfo($request->getPathInfo());
$this->setMethod($request->getMethod());
$this->setHost($request->getHost());
$this->setScheme($request->getScheme());
$this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
$this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
$this->setQueryString($request->server->get('QUERY_STRING', ''));
}
示例4: initializeRequestAttributes
protected function initializeRequestAttributes(Request $request, $master)
{
if ($master) {
// set the context even if the parsing does not need to be done
// to have correct link generation
$this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'is_secure' => $request->isSecure()));
}
if ($request->attributes->has('_controller')) {
// routing is already done
return;
}
// add attributes based on the path info (routing)
try {
$parameters = $this->router->match($request->getPathInfo());
if (null !== $this->logger) {
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
}
$request->attributes->add($parameters);
if ($locale = $request->attributes->get('_locale')) {
$request->getSession()->setLocale($locale);
}
} catch (NotFoundException $e) {
$message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
if (null !== $this->logger) {
$this->logger->err($message);
}
throw new NotFoundHttpException($message, $e);
} catch (MethodNotAllowedException $e) {
$message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
if (null !== $this->logger) {
$this->logger->err($message);
}
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
}
}
示例5: isSecure
/**
* {@inheritdoc}
*/
public function isSecure()
{
if (null !== $this->isSecure) {
return $this->isSecure;
}
if (parent::isSecure()) {
return $this->isSecure = true;
}
// It may happen that some misconfigured environments won't set
// the $_SERVER['HTTPS'] variable, we need another way to detect
// this, either using Drupal, or port in use.
if (443 === (int) $this->server->get('SERVER_PORT', 80)) {
return $this->isSecure = true;
}
// Worst than misconfigured, we actually have no idea about what's
// what because FPM or any other CGI gives us nothing goog to read,
// let's just trust Drupal and pray.
if ($GLOBALS['is_https']) {
return $this->isSecure = true;
}
// The Drupal base URL might have been hardcoded in settings.php so
// let's use that as last resort.
if ('https://' === substr($GLOBALS['base_url'], 0, 8)) {
return $this->isSecure = true;
}
return $this->isSecure = false;
}
示例6: isUrlLocal
public function isUrlLocal($link)
{
if (!$this->request) {
return false;
}
$parts = parse_url($link);
$isLocal = true;
if (!empty($parts['host']) && $parts['host'] !== $this->request->getHost()) {
$isLocal = false;
} elseif (!empty($parts['port']) && $parts['port'] !== $this->request->getPort()) {
$isLocal = false;
} elseif (!empty($parts['scheme']) && $this->request->isSecure() && $parts['scheme'] !== 'https') {
// going out from secure connection to insecure page on same domain is not local
$isLocal = false;
}
return $isLocal;
}
示例7: authenticationLogin
/**
* Login route.
*
* @param \Silex\Application $app
* @param Request $request
*
* @return Response
*/
public function authenticationLogin(Application $app, Request $request)
{
if (!$request->isSecure()) {
// Log a warning if this route is not HTTPS
$msg = sprintf("[ClientLogin][Controller]: Login route '%s' is not being served over HTTPS. This is insecure and vulnerable!", $request->getPathInfo());
$app['logger.system']->critical($msg, ['event' => 'extensions']);
}
$this->setFinalRedirectUrl($app, $request);
$response = $this->getFinalResponse($app, 'login');
return $response;
}
示例8: getName
/**
* Returns the session cookie name.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*
* @return string
* The name of the session cookie.
*/
protected function getName(Request $request)
{
// To prevent session cookies from being hijacked, a user can configure the
// SSL version of their website to only transfer session cookies via SSL by
// using PHP's session.cookie_secure setting. The browser will then use two
// separate session cookies for the HTTPS and HTTP versions of the site. So
// we must use different session identifiers for HTTPS and HTTP to prevent a
// cookie collision.
$prefix = $request->isSecure() ? 'SSESS' : 'SESS';
return $prefix . $this->getUnprefixedName($request);
}
示例9: setRequest
/**
* Sets all needed values from the request.
*
* @param Request $request A request to get values from.
*/
public function setRequest(Request $request)
{
$this->setScheme($request->getScheme());
$this->setHost($request->getHost());
$this->setBasePath($request->getBasePath());
if ($request->isSecure()) {
$this->setHttpsPort($request->getPort());
} else {
$this->setHttpPort($request->getPort());
}
}
示例10: sslRedirect
/**
* Checks if the user should be forced to use SSL connections.
*
* @param Request $request Request to check.
* @return boolean|\Symfony\Component\HttpFoundation\RedirectResponse False
* if the redirect is not needed and redirect response object otherwise.
*/
protected function sslRedirect(Request $request)
{
$need_redirect = Settings::get('enablessl') == '1' && Settings::get('forcessl') == '1' && !$request->isSecure();
if (!$need_redirect) {
return false;
}
if (null !== ($qs = $request->getQueryString())) {
$qs = '?' . $qs;
}
$path = 'https://' . $request->getHttpHost() . $request->getBasePath() . $request->getPathInfo() . $qs;
return $this->redirect($path);
}
示例11: handle
/**
* @param Request $request
* @return Response
*/
protected function handle(Request $request)
{
$vars = array('isSecure' => $request->isSecure());
if (array_key_exists('User', $_SESSION) && $_SESSION['User'] == "Default User" && plugin_find_id("auth") >= 0) {
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") {
$vars['protocol'] = "HTTPS";
} else {
$vars['protocol'] = preg_replace("@/.*@", "", @$_SERVER['SERVER_PROTOCOL']);
}
$vars['referrer'] = "?mod=browse";
$vars['authUrl'] = "?mod=auth";
}
return $this->render("home.html.twig", $this->mergeWithDefault($vars));
}
示例12: getLogin
/**
* Login page and "Forgotten password" page.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param boolean $resetCookies
*
* @return \Bolt\Response\BoltResponse|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function getLogin(Request $request, $resetCookies = false)
{
$user = $this->getUser();
if ($user && $user->getEnabled() == 1) {
return $this->redirectToRoute('dashboard');
}
if ($this->getOption('general/enforce_ssl') && !$request->isSecure()) {
return $this->redirect(preg_replace('/^http:/i', 'https:', $request->getUri()));
}
$response = $this->render('@bolt/login/login.twig', ['randomquote' => true]);
$response->setVary('Cookies', false)->setMaxAge(0)->setPrivate();
if ($resetCookies) {
$response->headers->clearCookie($this->app['token.authentication.name']);
}
return $response;
}
示例13: start
public function start(Request $request, AuthenticationException $authException = null)
{
$scheme = $request->isSecure() ? 'http' : 'https';
if ('http' === $scheme && 80 != $this->httpPort) {
$port = ':' . $this->httpPort;
} elseif ('https' === $scheme && 443 != $this->httpsPort) {
$port = ':' . $this->httpsPort;
} else {
$port = '';
}
$qs = $request->getQueryString();
if (null !== $qs) {
$qs = '?' . $qs;
}
$url = $scheme . '://' . $request->getHost() . $port . $request->getBaseUrl() . $request->getPathInfo() . $qs;
return new RedirectResponse($url, 301);
}
示例14: start
public function start(EventInterface $event, Request $request, AuthenticationException $authException = null)
{
$scheme = $request->isSecure() ? 'http' : 'https';
if ('http' === $scheme && 80 != $this->httpPort) {
$port = ':' . $this->httpPort;
} elseif ('https' === $scheme && 443 != $this->httpPort) {
$port = ':' . $this->httpsPort;
} else {
$port = '';
}
$qs = $request->getQueryString();
if (null !== $qs) {
$qs = '?' . $qs;
}
$url = $scheme . '://' . $request->getHost() . $port . $request->getScriptName() . $request->getPathInfo() . $qs;
$response = new Response();
$response->setRedirect($url, 301);
return $response;
}
示例15: initializeRequestAttributes
protected function initializeRequestAttributes(Request $request, $master)
{
if ($master) {
// set the context even if the parsing does not need to be done
// to have correct link generation
$this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'is_secure' => $request->isSecure()));
}
if ($request->attributes->has('_controller')) {
// routing is already done
return;
}
// add attributes based on the path info (routing)
if (false !== ($parameters = $this->router->match($request->getPathInfo()))) {
if (null !== $this->logger) {
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], str_replace("\n", '', var_export($parameters, true))));
}
$request->attributes->add($parameters);
if ($locale = $request->attributes->get('_locale')) {
$request->getSession()->setLocale($locale);
}
} elseif (null !== $this->logger) {
$this->logger->err(sprintf('No route found for %s', $request->getPathInfo()));
}
}