Welcome Guest, Not a member yet? Register   Sign In
How to use session
#1

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 ?
Reply
#2

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
Reply
#3

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
Reply
#4

When you change page, do you go from http://www to http://, if so that could be a reason why your session is lost.
Reply
#5

if session does not work how to create an authentification system ? With cookies ????
Reply
#6

Autoload the session library and read about sessions in the CodeIgniter Users Guide.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

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');
Reply
#8

InsiteFX means in /config/autoload.php
Reply
#9

how to do it. I want to go forward. 2 weeks now 3 weeks and I cannot use session in my productive server
Reply
#10

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
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB