Keep client logged in to http and https

Asked

Viewed 131 times

2

I’m finishing my virtual store developed in codeigniter 3 and database mysql is working perfectly. Now I want to start the digital certificate configuration.

My problem is this: when I go into the environment https right on the site all right, but when I return to the http it doesn’t keep the client logged in. How can I fix this? Or it is so and would have to do something else?

From now on thank you to all friends.

  • Out of curiosity, how do you force the SSL? In controllers or methods?

2 answers

1


Good morning buddy!

Adding this at the top of the "index" of each page the HTTPS is automatically triggered, say, passes from HTTP to HTTPS

<?
{
$new_url = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("Location: $new_url");
exit;
}


ForceHTTPS() //para chamar a função

?>

Any questions are available! Note: On my website is functional.

  • 1

    Good morning @marlonLeandro with this I solve the problem of being with an open session at http login or shopping cart type and will be passed to https.

  • 1

    It may depend on your login platform, on my website is functional so, the client logs into HTTPS and stays in HTTPS throughout the user’s platform, be it: client area, edit profile, etc. so that it is not disconnected by going from HTTPS to HTTP

1

Store all user data on $_SESSION. It will be available in any instance regardless of encryption.

Load the Session Library in scope or with autoload.

I’ve already made one helper who received the data from FORM after being so validated:

if( ! function_exists('session_set_userdata')){
    function session_set_userdata(){
        $ci = & get_instance();
        $controller = $ci->router->fetch_class();
        $method = $ci->router->fetch_method();
        unset($_SESSION['user']);
        $data = [
            'session' => sha1(date('H:m:i')),
            'logged' => TRUE,
            'captcha' => $ci->input->post('captcha'),
            'method' => $method,
            'controller' => $controller,
            'email' => $ci->input->post('email'),
            'ip_address' => $ci->input->ip_address(),
            'user_agent' => $ci->input->user_agent()
        ];
        $_SESSION['user'] = $data;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.