How to use session - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: How to use session (/showthread.php?tid=68198) Pages:
1
2
|
How to use session - kris - 06-08-2017 Hello I have the last stable version of codeigniter and try to use session. If someone is not authentified, I display the identification form. Something very classic but... My session works but only in the same page as soon as I change the page I loose it. Here is an example public function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->library('session'); $this->load->database(); $this->load->model('user_model'); //session_start(); // on controle ici si une session utilisateur existe echo "session ok!!!".$this->session->userapp; $userapp = $this->session->userdata('userapp'); //$userapp = $_SESSION['userapp1']; echo 'userapp '.$userapp; /*if($userapp == false || $userapp == NULL || empty($userapp )){ $url = site_url('/login'); echo '<br/><a href='.$url.'>'.$url.'</a>'; quit(); //redirect('login','refresh'); }*/ } ... it is always empty and here is my login function logincheck(){ echo '<br/>session.. '.$this->session->userapp; $uscode = $this->input->post('identifiant'); $erreur = 0; if ($data['r'] = $this->user_model->get_1userpercode($uscode)){ if ($data['r']['uspass'] == md5($this->input->post('mdp'))) { $this->session->set_userdata('userapp', $data['r']['uscode']); //$_SESSION['userapp1'] = $data['r']['uscode']; echo "session ok!".$this->session->userdata('userapp'); echo '<br/>session '.$this->session->userapp; } else { $erreur = 1; } } else { $erreur = 1; } On this login page, my session is ok I can see the user What should I do to use session On the manual I read Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key. what does that means ? I want to use session what shall I do ? shall I set an encryption key ? How ? RE: How to use session - kris - 06-09-2017 I must add information On local session works well On my host (dreamhost) it doesn't work. Each time I refresh my screen I have a new session. I tryed with php session not CI session and it works. I had php7 it didn't work I change to php56 and it is the same. I will use classic php session if I don't find any solution RE: How to use session - kris - 06-09-2017 No finaly with normal session it does not work. My session is lost. I cannot use session I don't know why. My project is locked. The only solution is to find an other host that keep session. I cannot make authentification ???? Do you have an idea ? I am completely lost RE: How to use session - Krycek - 06-09-2017 When you change page, do you go from http://www to http://, if so that could be a reason why your session is lost. RE: How to use session - kris - 06-09-2017 if session does not work how to create an authentification system ? With cookies ???? RE: How to use session - InsiteFX - 06-09-2017 Autoload the session library and read about sessions in the CodeIgniter Users Guide. RE: How to use session - kris - 06-09-2017 I red the documentation and follow it. It works localhost but as soon as I install on the production serveur. The session does not stay the same each time I refresh I have a new session. What do you mean my autoload ? I have this in my code $this->load->library('session'); RE: How to use session - Krycek - 06-09-2017 InsiteFX means in /config/autoload.php RE: How to use session - kris - 06-11-2017 how to do it. I want to go forward. 2 weeks now 3 weeks and I cannot use session in my productive server RE: How to use session - gabrielinbuon - 06-11-2017 Looks to me like you reset the session everytime. Best is to set only once using if set checker. If(!isset($this->session->userdata('auth'))){ Set the session here } |