I have my sessions configured to only use cookies, and to use a separate cookie for encrypted connections:
// only allow cookie based sessions
ini_set('session.use_only_cookies', TRUE);
// use a separate cookie for secure sessions
if(isset($_SERVER['HTTPS'])) {
ini_set('session.cookie_secure', TRUE);
} else {
ini_set('session.cookie_secure', FALSE);
}
$sess_prefix = ini_get('session.cookie_secure') ? 'SSL_' : '';
session_name($sess_prefix . 'PHPSESSID');
// start session
session_start();
All of the links on my site use relative paths. My question is, after a user is logged in how can I force all of the links to use HTTPS, and then go back to allowing HTTP after they logout?
I know I can force it on mandatory pages, for example:
if(!isset($_SERVER['HTTPS'])) {
header('Location: https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
}
But how would I handle conditional pages? When they're logged in I don't want to allow HTTP to be used at all.