At the moment I have SSL included on my server. Want to force my users to login using login-page via https.
<?php
if (empty($_SERVER['https']) || $_SERVER['https'] != 'on') {
header('location: https://my_login_page');
exit();
}
# rest of code
...
But it's a problem when there's no SSL.
Now I have situation. User requests following URL
http://domain.com/login.php
Here, I can't access to $_SERVER['https']
and want to make sure it's possible to redirect user to
https://domain.com/login.php
For example, SSL certificate expires after some time and want to keep users using login w/out secure connection.
My goal is something like this example:
if (ssl_installed() && (empty($_SERVER['https']) || $_SERVER[] != 'on')) {
header('location: https://domain.com/login.php');
exit();
}
# when there's no SSL it continues using HTTP
Yes, want to write function (example: ssl_installed()
) which returns true
when it's possible using secure connection, otherwise false
.
I've tried using get_headers()
and realized it always returns false against https://
links.
Possible solution:
I already have working solution. Config table in my database contains row ssl=1
(or 0) and after database connection has been established I'm using this value to decide is there possible to use SSL or not and function mentioned above uses this value to return result.
My question is: Is there simpler solution?
To be clear: I'm looking for PHP-ONLY SOLUTION (auto-detection)!
Any help would be appreciated.