Hi everyone,

I'm learning how to use cakePHP. Therefore, I created a small project
based on cakePHP 1.1.18.5850 with two controllers : Users and
Messages.

Users manages User authentification and when a user successfully logs
in, I try to put some information in session but it's lost everytime!
I set CAKE_SECURITY to "middle" or "low", CAKE_SESSION_TIMEOUT to 360
but I still have the same problem...
I also tried to save sessions differently ("database" or "cake"
instead of "php") but unsuccessfully...

I added the following method in my controllers in order to understand
what happens:
function beforeRender()
{
print_r($_SESSION);
}

I noticed that when I refreshed a page using Users controller, a new
session id was regenerated everytime.
On the contrary, if I refresh a page using Messages controller, the
session id doesn't change

Here is the code for Messages Controller
<?php
class MessagesController extends AppController
{
        var $name="Messages";
        var $components = array('Security');

        function index()
        {
                $this->set('messages', $this->Message->findAll());
        }

        function view($id=null)
        {
                $this->Message->id=$id;
                $this->data=$this->Message->read();
                if($this->data['Message']['received']=="0000-00-00 00:00:00")
                { //première consultation d'un message, on met le champ 
received à
jour
                        $now=date("Y-m-d H:i:s");
                        $this->Message->saveField("received",$now);
                        $this->data['Message']['received']=$now;
                }
                $this->set('message',$this->data);
        }

        function edit($id = null)
        {
                if(empty($this->data))
                {
                        $this->Message->id=$id;
                        $this->data=$this->Message->read();
                }
                else
                {
                        if($this->Message->save($this->data['Message']))
                        {
                                $this->flash('Message 
&eacute;dit&eacute;','/messages');
                        }
                }
        }

        function add()
        {
                if(empty($this->data))
                {
                        $this->set('sent',date("Y-m-d H:i:s"));
                }
                else
                {
                        if($this->Message->save($this->data))
                        {
                                $this->flash('Message 
ajout&eacute;','/messages');
                        }
                }
        }

        function del($id)
        {
                if($this->Message->del($id))
                {
                        $this->flash("Message supprim&eacute;",'/messages');
                }
        }

        function beforeRender()
        {
                print_r($_SESSION);
        }
}
?>

And here is the code for Users Controller

<?php
uses('Sanitize');
class UsersController extends AppController
{
        var $name="Users";
        var $components = array('Security');

        function index()
        {
                if($this->Session->check("loggedIn") && $this->Session-
>check("user"))
                {
                        //this part doesn't work because session data is 
destroyed when
this controller is used
                        $this->flash("Acc&egrave;s &agrave; la boite de 
reception","/
messages");
                }
                elseif(!empty($this->data) && 
$this->User->validates($this->data))
                {
                        $user=$this->User->find("id='".Sanitize::paranoid($this-
>data['User']['id'])."'","password",null,0);

                        if(!empty($user) && 
$user['User']['password']==md5($this-
>data['User']['password']))
                        {
                                if($this->Session->valid())
                                {
                                        //enregistre les infos en session
                                        
$this->Session->write('user',$this->data['User']['id']);
                                        $this->Session->write('loggedIn',true);
                                        print_r($_SESSION);
                                        $this->flash("Identification 
effectu&eacute;e avec
succ&egrave;s","/messages");
                                }
                                else
                                {
                                        //problème session
                                        $this->flash("Session 
invalide","/users/login");
                                }
                        }
                }
                elseif(!empty($this->data) && 
!$this->User->validates($this->data))
                {
                        //erreur dans formulaire identification
                        $this->validateErrors($this->User);
                }
        }

        function beforeRender()
        {
                print_r($_SESSION);
        }
}
?>

Thank you for your help :)

Regards,

romain


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to