Slim.url_scheme always showing http even accessed from https

Hi All,

I want restrict to allow only https. So, I am trying to add condition by checking slim.url_scheme. But slim.url_scheme always showing http even I accessed from https. Can you please help what i need to modify.

Thanks

I don’t know if there is a way to force https via Slim (newbie), but if you have access to the server, specifically httpd.conf or vhosts (in Apache), you can use: Redirect permanent / https://urlGoesHere in the <VirtualHost *:80> section. Else, I would use PHP code to redirect:

if ($_SERVER[‘SERVER_PORT’] != 443) {
$redir = “Location: https://” . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘PHP_SELF’];
header($redir);
exit();
}

From request you can pick up connection protocol like this

$request->getUri()->getScheme()

This works very well.

1 Like