Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:05:25+00:00 2026-06-17T15:05:25+00:00

I have problems with a session variable, users log into the app and then

  • 0

I have problems with a session variable, users log into the app and then it sets a session variable but when it redirects to the next controller it isn’t there.

At the moment I am not using the auth component, I think it is not correct, but I don’t know how to apply it to my logic. This is because I dont log in users with username and password, they come authenticated from other website that gives me a ticket and a key to know who they are.

Here is my code of the UsersController where the app starts:

class UsuariosController extends AppController {
public $components = array('Session');

function beforeFilter() {

}

function login() {
    $isLogged = false;
    if(!empty($_POST['Ffirma']) ) {
        $this->loginByTicket();
    }
    else if(!empty($this->data)) { //When users log by email it works perfectly
        $this->loginByEmail();
    }
}

private function loginByEmail() {
    //Se busca el usuario en la base de datos
    $u = new Usuario();
    $dbuser = $u->findByEmail($this->data['Usuario']['email']);

    //if doesn't exist user in db
    if(empty($dbuser) ) {
        $this->Session->setFlash('El usuario no existe en el sistema, consulte con el administrador.');
        $this->redirect(array('controller' => 'usuarios', 'action' => 'login'));
        exit();
    }
    $this->userIsCorrectlyLogged($dbuser);
}

function loginByTicket() {
    $Fip = $_POST['Fip'];
    $Frol = $_POST['Frol'];
    $FidPersona = $_POST['Fidpersona'];
    $Fticket = $_POST['Fticket'];
    $Ffirma = $_POST['Ffirma'];
    //Check sing
    $f = $this->gen_firma($Frol, $FidPersona,  $Fticket);
    if( strcmp($f, $Ffirma) != 0 ) {
        $this->Session->setFlash('Firma no válida.');
        return;
    }
    //Check if ticket is valid
    //1º Check if it exists on the db
    $t = split('-',$Fticket);
    $ticket = new Ticket();
    $dbticket = $ticket->findById($t[0]);
    if( strcmp($dbticket['Ticket']['valor'], $t[1]) != 0) {
        $this->Session->setFlash('Ticket no válido.');
        return;
    }

    //2º if Ip ok
    if($Fip != $dbticket['Ticket']['ip']) {
        $this->Session->setFlash('IP no válida.'.' '.$dbticket['Ticket']['ip'].' '.$Fip);
        return;
    }

    $u = new Usuario();
    $dbuser = $u->findById($dbticket['Ticket']['idPersona']);
    $this->userIsCorrectlyLogged($dbuser);
}

private function userIsCorrectlyLogged($dbuser) {
    $user = array('Usuario' => array(
        'last_login' => date("Y-m-d H:i:s"),
        'rol_app' => 1,
        'nombre' => $dbuser['Usuario']['nombre'],
        'email' => $dbuser['Usuario']['email'],
        'apellidos' => $dbuser['Usuario']['apellidos'],
        'id' => $dbuser['Usuario']['id']
    ) );
    //Some stuff to determine rol privileges
    $this->Session->destroy(); 
    $this->Session->write('Usuario', $user);
    $this->redirect(array('controller' => 'mains', 'action' => 'index'),null, true);
    exit();
}

As you can see I make some controls before know that the user is correctly logged, and in user correctly logged I just save the session.

In my AppController I check if the user has logged in, but the session variable has already gone:

class AppController extends Controller {
    public $components = array('Session');
    function beforeFilter() {
        //Configure::write('Security.level', 'medium'); //I've tried this that i saw somewhere
        pr($this->Session->read()) // Session is empty
        if($this->checkAdminSession()) {
            $user = $this->Session->read('Usuario');
            $email = $user['Usuario']['email'];
            $usuario = new Usuario();
            $dbuser = $usuario->findByEmail($email);
            $respons = $usuario->getAccionesResponsable($dbuser['Usuario']['id']);  
            $this->set("hayacciones", true);
            if( empty($respons) ) $this->set("hayacciones", false);
        }
        else {
           $this->Session->setFlash('Necesitas identificarte para acceder al sistema.');

           $this->redirect('/usuarios/login/');
           exit();
        }
}
    function checkAdminSession() {
        return $this->Session->check('Usuario');        
    }
}

I’m desperate, I’ve read a lot of documentation but I don’t know how to solve this problem, could you give me any clue?

Thanks you very much, and sorry for my English!.

Note: I have discovered that if the security level is low it works:

Configure::write('Security.level', 'low');

But I dont like this solution…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:05:26+00:00Added an answer on June 17, 2026 at 3:05 pm

    I have the same problem. I tried all the suggestion. My Cache engine is Apc.

      $this->__saveData($t);
      debug($this->Session->read());// >>>>>> GOOD
      $this->redirect(array('controller'=>'users','action'=>'main'));
        }
    }
     }
      function logout() {
        $this->Session->destroy();
                $this->Session->delete('User');
        $this->redirect(array('controller'=>'logins','action'=>'login'));
    }
    function forgot() {
    $this->layout = 'login';
    
    } 
        private function __saveData($t)
        {   
             $this->Session->write('User',$t['User']['name']);
             $this->Session->write('User_name',$t['User']['firstname']);
             $this->Session->write('User_id',$t['User']['id']);
             $this->Session->write("User_Group",$t['Group']['name']);
             $g = $this->Myauth->getPerm('User_Group'); // This is the array of permission w.r.t to the menu (key)
             $this->Session->write("Permissions",$g);
    
             debug($this->Session->read());
        }
     function main()
    {
        // Check permissions
    $this->Myauth->check('users','login');
    $username   = $this->Session->read('User');
    debug($this->Session->read( ));die(); <<<<< NOTHING
    

    }

    The funny thing is that yesterday it worked.

    My php.ini has a simple extension=apc.so.
    My core.php

        Configure::write('Session.defaults', 'php');
    

    Nothing change if I change the Security level. I will appreciate any direction.

    EDIT
    First solution: in my php.ini I had a bad value for session.referer_check (It was = 0 while it should be ”).
    But now, on the same server, one site is ok. Another one fires the error
    Error: Call to undefined function apc_cache_info()

    The two sites are separated and do not share any cakelib.

    [SOLUTION FOUND]

    For Cake > 2.2 and Chrome 24 I found this solution (I tried all the others found on the web). In your core.php:

         Configure::write('Security.cookie', 'cakephpfdebackend');
         Configure::write('Session.cookieTimeout', 0);
         Configure::write('Session.checkAgent', false);
         Configure::write('Session.cookie_secure',false);
         Configure::write('Session.referer_check' ,false);
         Configure::write('Session.defaults', 'php'); 
    

    Actually, only the Session.cookieTimeout is required. The other settings are optional to solve the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searched and found a lot of similar problems with session variable being set
I have an asp.net application c# that uses session state to store a variable
I have problems when overriding passwords controller in devise. I do not want to
I have a log in page where I valid my users and based on
I have a problem with using session variable in the page_load . I have
I have secured pages that all check for a set session variable to determine
I have CentOS LAMP with multiple sites. I use PHP session variable for the
I have a bizarre problem. I use a lot of session variables so I
I have problem with session in cakephp.I have one file chat.php that is in
i have a problem with session in my webapplication (asp.net mvc rc2). the application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.