本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::setTrustedProxies方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setTrustedProxies方法的具体用法?PHP Request::setTrustedProxies怎么用?PHP Request::setTrustedProxies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::setTrustedProxies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
public function boot()
{
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
Request::setTrustedProxies($trustedProxies);
} elseif ($this->container->getParameter('kernel.trust_proxy_headers')) {
Request::trustProxyData(); // @deprecated, to be removed in 2.3
}
}
示例2: setProxyConf
public function setProxyConf()
{
if (!$this->configuration->isSetup()) {
return;
}
$proxies = isset($this->configuration['trusted-proxies']) ? $this->configuration['trusted-proxies'] : [];
Request::setTrustedProxies($proxies);
}
示例3: boot
public function boot()
{
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
Request::setTrustedProxies($trustedProxies);
}
if ($this->container->getParameter('kernel.http_method_override')) {
Request::enableHttpMethodParameterOverride();
}
}
示例4: init
/**
*/
public static function init()
{
if (!static::$request) {
Request::setTrustedProxies(Constants::$trusted_proxies);
// Create request object from global page request otherwise.
static::$request = Request::createFromGlobals();
}
// Otherwise, the request will be pre-injected.
}
示例5: boot
public function boot()
{
ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
Request::setTrustedProxies($trustedProxies);
}
if ($this->container->getParameter('kernel.http_method_override')) {
Request::enableHttpMethodParameterOverride();
}
if ($trustedHosts = $this->container->getParameter('kernel.trusted_hosts')) {
Request::setTrustedHosts($trustedHosts);
}
}
示例6: testListenerThrowsWhenMasterRequestHasInconsistentClientIps
/**
* @expectedException Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException
*/
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'));
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', '2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
$dispatcher->addListener(KernelEvents::REQUEST, array(new ValidateRequestListener(), 'onKernelRequest'));
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}
示例7: testUseRequestClientIp
public function testUseRequestClientIp()
{
Request::setTrustedProxies(array('192.168.0.1'));
list($event, $server) = $this->createRequestEvent(array('X_FORWARDED_FOR' => '192.168.0.2'));
$processor = new WebProcessor();
$processor->onKernelRequest($event);
$record = $processor($this->getRecord());
$this->assertCount(5, $record['extra']);
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
$this->assertEquals($server['X_FORWARDED_FOR'], $record['extra']['ip']);
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
}
示例8: signup
/**
* The signup action processes a signup request and creates new accounts
*
* @return ViewSpec
*/
public function signup()
{
Request::setTrustedProxies(Constants::$trusted_proxies);
$request = Request::createFromGlobals();
$signupRequest = $this->buildSignupRequest($request);
try {
$this->validateSignupRequest($signupRequest);
// guard method
$viewSpec = $this->doWork($signupRequest);
} catch (\RuntimeException $e) {
$viewSpec = $this->renderException($e, $signupRequest);
}
return $viewSpec;
}
示例9: initServiceProviders
protected function initServiceProviders()
{
$app = $this;
if ($this['config']['trusted_proxies']) {
\Symfony\Component\HttpFoundation\Request::setTrustedProxies($this['config']['trusted_proxies']);
}
$app['app_base_path'] = $this->basePath;
$app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.options' => array('cache' => $this->basePath . '/cache/twig', 'auto_reload' => $this['debug'], 'strict_variables' => true), 'twig.path' => array($this->basePath . '/src/views')));
$app->register(new \Silex\Provider\SwiftmailerServiceProvider());
$app->register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', array()));
$app['mongodb.database'] = $app->share(function ($app) {
return $app['mongodb.connection']->selectDatabase($app['config']['mongo']['db_name']);
});
$app->register(new \Devture\Bundle\FrameworkBundle\ServicesProvider($this['config']['FrameworkBundle']));
$app->register(new \Devture\Bundle\LocalizationBundle\ServicesProvider($app['config']['LocalizationBundle']));
$app->register(new \Devture\Bundle\UserBundle\ServicesProvider($app['config']['UserBundle']));
$app->register(new \Devture\Bundle\NagiosBundle\ServicesProvider($app['config']['NagiosBundle']));
}
示例10: perform_login_if_requested
/**
* Perform all the login functionality for the login page as requested.
*/
public static function perform_login_if_requested($username_requested, $pass)
{
Request::setTrustedProxies(Constants::$trusted_proxies);
$request = Request::createFromGlobals();
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$login_attempt_info = ['username' => $username_requested, 'user_agent' => $user_agent, 'ip' => $request->getClientIp(), 'successful' => 0, 'additional_info' => $_SERVER];
$logged_in = login_user($username_requested, $pass);
$is_logged_in = $logged_in['success'];
if (!$is_logged_in) {
// Login was attempted, but failed, so display an error.
self::store_auth_attempt($login_attempt_info);
$login_error_message = $logged_in['login_error'];
return $login_error_message;
} else {
// log a successful login attempt
$login_attempt_info['successful'] = 1;
self::store_auth_attempt($login_attempt_info);
return '';
}
}
示例11: loadConfig
/**
* @param string $configFile path to main configuration file
*/
public function loadConfig($configFile)
{
$yaml = new Parser();
try {
$config = $yaml->parse(file_get_contents($configFile));
} catch (ParseException $e) {
$this->logger->critical('Unable to parse the YAML string: ' . $e->getMessage() . ' in ' . $e->getParsedFile());
return;
}
if (!is_array($config)) {
$this->logger->critical('Parsed config file is not an array');
return;
}
$config = $this->configurator->resolveMainConfig($config);
//trusted proxies
if (array_key_exists('trustedProxies', $config)) {
$arrayOfProxies = is_string($config['trustedProxies']) ? array($config['trustedProxies']) : $config['trustedProxies'];
Request::setTrustedProxies($arrayOfProxies);
}
//global hook options
if (array_key_exists('options', $config)) {
$this->options = $this->configurator->resolveOptions($config['options']);
}
// global hook commands
if (array_key_exists('commands', $config)) {
$this->addCommand($config['commands']);
}
// global path
if (array_key_exists('path', $config)) {
$this->path = $config['path'];
}
// configure global repositories
if (array_key_exists('repositories', $config)) {
$this->handleRepositoryConfig($config);
}
// configure repositoriesDir
if (array_key_exists('repositoriesDir', $config)) {
$this->loadRepos($config['repositoriesDir']);
}
}
示例12: update_activity_info
/**
* Update the information of a viewing observer, or player.
*/
function update_activity_info()
{
// ******************** Usage Information of the browser *********************
Request::setTrustedProxies(Constants::$trusted_proxies);
$request = Request::createFromGlobals();
$remoteAddress = '' . $request->getClientIp();
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 250) : NULL;
// Truncated at 250 char.
$referer = isset($_SERVER['HTTP_REFERER']) ? substr($_SERVER['HTTP_REFERER'], 0, 250) : '';
// Truncated at 250 char.
// ************** Setting anonymous and player usage information
DatabaseConnection::getInstance();
$session = SessionFactory::getSession();
if (!$session->has('online')) {
// *** Completely new session, update latest activity log. ***
if ($remoteAddress) {
// *** Delete prior to trying to re-insert into the people online. ***
$statement = DatabaseConnection::$pdo->prepare('DELETE FROM ppl_online WHERE ip_address = :ip OR session_id = :sessionID');
$statement->bindValue(':ip', $remoteAddress);
$statement->bindValue(':sessionID', $session->getId());
$statement->execute();
}
// *** Update viewer data. ***
$statement = DatabaseConnection::$pdo->prepare('INSERT INTO ppl_online (session_id, activity, ip_address, refurl, user_agent) VALUES (:sessionID, now(), :ip, :referer, :userAgent)');
$statement->bindValue(':sessionID', $session->getId());
$statement->bindValue(':ip', $remoteAddress);
$statement->bindValue(':referer', $referer);
$statement->bindValue(':userAgent', $userAgent);
$statement->execute();
$session->set('online', true);
} else {
// *** An already existing session. ***
$statement = DatabaseConnection::$pdo->prepare('UPDATE ppl_online SET activity = now(), member = :member WHERE session_id = :sessionID');
$statement->bindValue(':sessionID', $session->getId());
$statement->bindValue(':member', is_logged_in(), PDO::PARAM_BOOL);
$statement->execute();
}
}
示例13: initMountpoints
public function initMountpoints()
{
if ($proxies = $this['config']->get('general/trustProxies')) {
Request::setTrustedProxies($proxies);
}
// Mount the 'backend' on the branding:path setting. Defaults to '/bolt'.
$backendPrefix = $this['config']->get('general/branding/path');
$this->mount($backendPrefix, new Controllers\Login());
$this->mount($backendPrefix, new Controllers\Backend());
// Mount the 'async' controllers on /async. Not configurable.
$this->mount('/async', new Controllers\Async());
// Mount the 'thumbnail' provider on /thumbs.
$this->mount('/thumbs', new Thumbs\ThumbnailProvider());
// Mount the 'upload' controller on /upload.
$this->mount('/upload', new Controllers\Upload());
// Mount the 'extend' controller on /branding/extend.
$this->mount($backendPrefix . '/extend', $this['extend']);
if ($this['config']->get('general/enforce_ssl')) {
foreach ($this['routes'] as $route) {
/** @var \Silex\Route $route */
$route->requireHttps();
}
}
// Mount the 'frontend' controllers, as defined in our Routing.yml
$this->mount('', new Controllers\Routing());
}
示例14: umask
use Symfony\Component\HttpFoundation\Request;
/**
* @var Composer\Autoload\ClassLoader
*/
$loader = (require __DIR__ . '/../app/autoload.php');
include_once __DIR__ . '/../app/bootstrap.php.cache';
if (extension_loaded('apc') && ini_get('apc.enabled')) {
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
}
if (getenv('APP_ENV') === 'dev') {
umask(00);
Debug::enable();
$kernel = new AppKernel('dev', true);
} else {
$kernel = new AppKernel('prod', false);
}
$kernel->loadClassCache();
if (getenv('APP_ENV') !== 'dev') {
if (!isset($_SERVER['HTTP_SURROGATE_CAPABILITY']) || false === strpos($_SERVER['HTTP_SURROGATE_CAPABILITY'], 'ESI/1.0')) {
require_once __DIR__ . '/../app/AppCache.php';
$kernel = new AppCache($kernel);
}
}
Request::enableHttpMethodParameterOverride();
Request::setTrustedProxies(array('127.0.0.1'));
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
示例15: ApcClassLoader
$loader = new ApcClassLoader($prefix ?: "ezpublish", $loader);
$loader->register(true);
}
require_once __DIR__ . '/../ezpublish/EzPublishKernel.php';
if ($useDebugging) {
Debug::enable();
}
$kernel = new EzPublishKernel($environment, $useDebugging);
// we don't want to use the classes cache if we are in a debug session
if (!$useDebugging) {
$kernel->loadClassCache();
}
// Depending on the USE_HTTP_CACHE environment variable, tells whether the internal HTTP Cache mechanism is to be used.
// If not set it is activated if not in "dev" environment.
if (($useHttpCache = getenv("USE_HTTP_CACHE")) === false) {
$useHttpCache = $environment !== "dev";
}
// Load HTTP Cache ...
if ($useHttpCache) {
require_once __DIR__ . '/../ezpublish/EzPublishCache.php';
$kernel = new EzPublishCache($kernel);
}
$request = Request::createFromGlobals();
// If you are behind one or more trusted reverse proxies, you might want to set them in TRUSTED_PROXIES environment
// variable in order to get correct client IP
if (($trustedProxies = getenv("TRUSTED_PROXIES")) !== false) {
Request::setTrustedProxies(explode(",", $trustedProxies));
}
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);