I have done with all the settings about the Session time out.
Core.php
Configure::write('Session', array(
'defaults' => 'cake',
'timeout' => '180',
'cookieTimeout' => '180',
'autoRegenerate' => true,
'ini' => array(
'session.cookie_secure' => false
)
));
Configure::write('Security.level', 'low');
But still the user is getting logged out after 24 mins of inactivity.
Also the cookei expiration time is not updating on every request. I have made some changes in the Cakesession.php
public static $requestCountdown = 1;
But still no luck. Can anybody focus light on the issue?
Related
I'm working on a project which only a few packages of cake 3 :
cakephp/orm
cakephp/validation
cakephp/i18n
cakephp/cache
I just installed the last one (cache).
I uploaded my project to a production server, and was surprised to see that my queries using the ORM are extremely slow (a query that lasts about 100ms on my local machine can take up to 5 or 10 seconds on the production server).
It seems that there are queries on the information_schema table that take much time and resources. So I've went on the web and saw that I needed the enable cacheMetaData param in my config.
My config looks like this :
ConnectionManager::config('default', [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'my-host',
'database' => 'my-database',
'username' => 'my-username',
'password' => 'my-password',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetaData' => true // If set to `true` you need to install the optional "cakephp/cache" package.
]);
I followed the instruction above and installed the cakephp/cache package. But I'm guessing I need to enable it somehow (or somewhere), but can't figure out how (or where).
Here is what I tried :
\Cake\Cache\Cache::config('_cake_model_', [
'className' => 'File',
'prefix' => 'myapp_cake_model_',
'path' => '/cache/models/',
'serialize' => true,
'duration' => '+2 minutes',
]);
But it's still not working, my cache or cache/models/ folder is still empty and the requests are taking a long time.
How can I fix this ?
Thanks for your time
kinkaz
For a detailed solution on this topic, please see http://discourse.cakephp.org/t/orm-cache-metadata-issue/1071
I have a CakePHP application (v 2.7), which contains a fairly standard login element using the Auth component. This works fine for the majority of users, however, a handful of users are reporting that they cannot sign in - when they attempt to do so they are redirected back to the login page, with no error message.
I have built some logging in to the site to check what is happening and it seems that the login is going through fine (everything in my login action is logged working as desired) until they hit the redirect part of the code, then they are not redirected to the intended page.
All the users who are having problems seem to be coming to the site through the same company network - not sure if that's of relevance or not! However, all have cookies enabled (I have added a script to display an error if they are not enabled).
I have tested the site in IE11, Edge 11, 12 + 13 (the browsers that users appear to be having issues with) but cannot replicate the issue, regardless of the security settings on the browser.
Could this issue be related to settings in the network that the users are accessing the site from? Are there any settings I should try to get them to check? Sorry - I'm pretty stumped by this one, as I just cannot replicate it, any pointers towards the questions I should be asking would be useful.
The relevant sections of my code are below. If there are any bits that would be helpful please let me know.
Thanks in advance for any help.
In the AppController (components)
public $components = array(
'Session',
'Cookie',
'Security' => array(
'csrfExpires' => '+300 minutes',
'csrfUseOnce' => false
),
'Auth' => array(
'loginAction' => array('controller' => 'users', 'action' => 'login', 'admin' => false),
'loginRedirect' => array('controller' => 'course_sections', 'action' => 'index', 'admin' => false),
'logoutRedirect' => array('controller' => 'website_pages', 'action' => 'view', 'home', 'admin' => false),
'authorize' => array('Controller'),
'authenticate' => array(
'all' => array(
'scope' => array('User.is_archived' => 0, 'Client.is_active' => 1),
'contain' => array('UserGroup'),
'passwordHasher' => 'Blowfish'
),
'Form' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
)
)
),
'Acl'
);
In the UsersController
public function login(){
// If user has submitted the form
if ($this->request->is(array('post', 'put'))) {
if ($this->Auth->login()) {
$this->log('Successfully logged in. Cookie Status: ' . $this->request->data['User']['cookies'], $this->Auth->user('public_id'));
// Redirect
return $this->redirect($this->Auth->redirectUrl());
} else {
// Log failed login attempt
$this->log('Unsusccessful login attempt using email: ' . $this->request->data['User']['email'], 'nosuccess');
$this->Session->setFlash($this->FlashMessage->translateFlash('invalid_login', false));
}
}
}
I am using database backed sessions, but the issue is the same whether using these or PHP ones.
I'm working on my first app w/ CakePHP 2.3 and I'm having an issue where I can login (no auth errors), but my session isn't sticking around so I'm sent back to the login page when the Auth->redirect() is called. I'm sure I'm just missing a setting or have something configured slightly wrong, but I haven't been able to find it.
# core.php
# session record is written the the database, but the same record's id changes w/ every request
Configure::write('Session', array(
'defaults' => 'database',
));
Configure::write('Security.level', 'medium');
I've tried tweaking the various Session.X parameters, but nothing has made any difference. I'm using bcrypt authentication with the following settings in my AppController:
'Auth' => array(
'authenticate' => array(
'Blowfish' => array(
'fields' => array( 'username' => 'email' ),
'scope' => array( 'active' => '1' )
),
),
'authorize' => array( 'Controller' ),
'loginAction' => array( 'admin' => false, 'controller' => 'users', 'action' => 'login' ),
'loginRedirect' => array( 'admin' => true, 'controller' => 'activities', 'action' => 'index' ),
'logoutRedirect' => array( 'admin' => false, 'controller' => 'users', 'action' => 'login' ),
),
What piece am I missing?
UPDATE
Realizing that this is only happening in my dev environment, I compared my Cake config (database, core, bootstrap) and php.ini values -- no differences. I'm stumped.
Holy Headslap, Batman.
So here's the issue. I'm storing sessions in the database. Somewhere, somehow, an (obviously) automated process changed the cake_sessions.data field to cake_sessions.DATA. Although I've looked at the database a thousand times while debugging this, I just noticed that difference.
Problem solved.
Moral of the story: Developers, don't let your database field names grow up and change case.
You need to set 'Session' as a component too.
I have one database - (users, administrators).
I have 2 app. (application/login, backend/login).
So, when I log in at "backend" with my administrator data, I don't want to be logged in with that SAME data on "application".
How can I get two different sessions for two different applications in CakePHP under the same browser?
I want to be logged in with administrators under /backend and with user under /application.
CakePHP 2.2.0.
Thank you all. :)
Solved it. In app/Config/core.php:
Application:
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => '/application',
),
'cookie' => 'my_cookie',
));
Backend:
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => '/backend',
),
'cookie' => 'my_cookie_2',
));
Thanks anyway. :D I've learned a lot in this few hours. :D
I am quite new to cakephp and I'm having trouble getting it configured to work on my live server. It works fine on my local machine.
I think the problem is that my live server is configured to use Memcache. When I visit the live site I get:
Warning (2): session_start() [function.session-start]: open(=1&retry;_interval=15/sess_mt8tpui04vorqojg7s945e5sf5, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Model/Datasource/CakeSession.php, line 615]
Warning (2): session_write_close() [function.session-write-close]: open(=1&retry;_interval=15/sess_mt8tpui04vorqojg7s945e5sf5, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Controller/Controller.php, line 712]
Warning (2): session_write_close() [function.session-write-close]: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (tcp://127.0.0.1:11211?persistent=1&weight;=1&timeout;=1&retry;_interval=15) [CORE/Cake/Controller/Controller.php, line 712]
So i've tried enabling cake to use memcache by adding the following to app/Config/core.php:
Cache::config('default', array(
'engine' => 'Memcache'
));
But I still get the same error.
The php.ini is configured to use memcache correctly.
Any ideas?
Thanks
Your Cache::config looks incomplete!
It should look like this and This code block will be in app/Config/bootstrap.php
Cache::config('default', array(
'engine' => 'Memcache', //[required]
'duration' => 3600, //[optional]
'probability' => 100, //[optional]
'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
'servers' => array(
'127.0.0.1:11211' // localhost, default port 11211
), //[optional]
'persistent' => true, // [optional] set this to false for non-persistent connections
'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
));
Also you need to set a session handler http://book.cakephp.org/2.0/en/development/sessions.html#cache-sessions
Mine looks like this, note that I have called "sessiones"
& This code block will be in app/Config/core.php
Configure::write('Session', array(
'defaults' => 'cache',
'handler' => array(
'config' => 'sessiones'
),
'cookie' => 'PHPSESSID',
'timeout' => 3600,
'cookieTimeout' => 0,
'autoRegenerate' => false,
'checkAgent' => true,
'ini' => array(
'session.cookie_secure' => false,
'session.cookie_httponly' => true,
)
));
And then set up the Cache:config for the handler "sessiones"
and This code block will be in app/Config/bootstrap.php
Cache::config('sessiones', array('engine' => 'Memcache','duration'=> 3600,/*'prefix' =>'es',*/ 'servers' => array(array('127.0.0.1:11211'), 'compress' => false));