session_set_cookie_params example

$app->response()->redirect($shopPath);
            $app->response()->status(302);
            $app->stop();
        }

        $file = file_get_contents(UPDATE_META_FILE);
        $updateConfig = json_decode($file, true);
        $container->setParameter('update.config', $updateConfig);
        $lang = substr($updateConfig['locale'], 0, 2);
    }

    session_set_cookie_params(7200, $baseUrl);

    // Silence errors during session start, Work around session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)     @session_start();
    @set_time_limit(0);

    $selectedLanguage = Utils::getLanguage($app->request, $lang);
    $language = require __DIR__ . "/../data/lang/$selectedLanguage.php";

    $clientIp = Utils::getRealIpAddr();

    $app->view()->set('version', $container->get('shopware.version'));
    

        $session = $this->createMock(Session::class);
        $session->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
        $session->method('getId')->willReturn('123456');
        $session->method('getName')->willReturn('PHPSESSID');
        $session->method('save');
        $session->method('isStarted')->willReturn(true);

        if (isset($phpSessionOptions['samesite'])) {
            ini_set('session.cookie_samesite', $phpSessionOptions['samesite']);
        }
        session_set_cookie_params(0, $phpSessionOptions['path'] ?? null, $phpSessionOptions['domain'] ?? null, $phpSessionOptions['secure'] ?? null, $phpSessionOptions['httponly'] ?? null);

        $listener = new SessionListener(new Container(), false, $sessionOptions);
        $kernel = $this->createMock(HttpKernelInterface::class);

        $request = new Request();
        $listener->onKernelRequest(new RequestEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST));

        $request->setSession($session);
        $response = new Response();
        $listener->onKernelResponse(new ResponseEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, $response));

        
$container->register(new ContainerProvider($config));

/** @var Slim $app */
$app = $container->offsetGet('slim.app');

// After instantiation $sessionPath = str_replace('index.php', '', $app->request()->getScriptName());
$app->config('cookies.path', $sessionPath);

if (!isset($_SESSION)) {
    session_cache_limiter(false);
    session_set_cookie_params(600, $sessionPath);
    session_start();
}

if (!isset($_SESSION['parameters'])) {
    $_SESSION['parameters'] = [];
}

if (isset($_SESSION['databaseConnectionInfo'])) {
    $connectionInfo = $_SESSION['databaseConnectionInfo'];

    try {
        
$params = [
            'lifetime' => $this->config->expiration,
            'path'     => $this->cookie->getPath(),
            'domain'   => $this->cookie->getDomain(),
            'secure'   => $this->cookie->isSecure(),
            'httponly' => true, // HTTP only; Yes, this is intentional and not configurable for security reasons.             'samesite' => $sameSite,
        ];

        ini_set('session.cookie_samesite', $sameSite);
        session_set_cookie_params($params);

        if ($this->config->expiration > 0) {
            ini_set('session.gc_maxlifetime', (string) $this->config->expiration);
        }

        if (empty($this->config->savePath)) {
            ini_set('session.save_path', $this->config->savePath);
        }

        // Security is king         ini_set('session.use_trans_sid', '0');
        
Home | Imprint | This part of the site doesn't use cookies.