I am using this configuration in core.php:
Configure::write('Session', array(
'defaults' => 'php'
));
Configure::write('Session.save', 'custom_session_handler');
/**
* The level of CakePHP security.
*/
Configure::write('Security.level', 'high');
And custom_session_handler.php (in app/config)
<?php
ini_set('session.cookie_lifetime', 0);
?>
When I close browser session should be destroyed/not remembered - but it doesn't work, when I close browser I am still logged in...
I am using Auth component, cakePHP 2.0, php 5.3.9 on WAMP server on my PC.
And moreover in my php.ini Session.cookie_lifetime is set to 0 by default
I found it - it should be:
Configure::write('Session', array(
'defaults' => 'php',
'cookieTimeout' => 0,
));
Related
My cakephp session cookie using PHPSESSID instead of user defined
here is the image, i try to get session name used by this application debug(session_name());, it show PHPSESSID instead of makassarterkini
is there something i need to configure in php.ini?
Take a look at your CakePHP session configuration.
For example:
//core.php
Configure::write('Session', array(
'defaults' => 'php',
'cookie' => 'stackoverflowexample',
'timeout' => '43200',
'cookieTimeout' => '43200'
));
I can access this session using:
$this->Session->read('stackoverflowexample.somevalue');
I am using Auth Session in CakePHP.
'Session' => [
'timeout' => 0,
'defaults' => 'php',
'ini' => [
'session.cookie_secure' => false,
'session.cookie_lifetime' => 0
]
],
Already configured this in tha app.php but still getting logged out after few minutes.
Although Session persists when closing Browser. So i think its just a time related problem.
I was having requirement to increase session timeout in cakphp 2.5
the following code worked for me in 2.5 you can give this a try
//FILE: config/core.php
Configure::write('Session', array(
'defaults' => 'cake',
'cookie' => 'my_app',
'timeout' => 500, // 8 hours + 20 min, user will be logged in till 8 hours.
)
);
Here is my code to set cookie
$cookie = array(
'name' => 'City',
'value' => $city,
'expire' => 86400 * 30,
'domain' => '.localhost',
'path' => '/',
'prefix' => 'picker_',
);
$this->input->set_cookie($cookie)
and i loading cookie helper in constructor of a controller.
my cookie is set form 1 month and i check in browser my cookie is set name
'City' and value = '10'. the problem is when i retrieve the value i get the blank page nothing is printing
here the code of fetching value
echo $this->input->cookie('picker_City');
i also try var_dump
var_dump($this->input->cookie('City', false));
it return false
what is the error.
You have to load the helper cookie first before using set_cookie
$this->load->helper('cookie');
and then use set_cookie
If you are using cookies very often , its better you load it in the autoload.php in the config folder.
in the autoload array
$autoload['helper'] = array('cookie');
Did you load it?
NOTE:
For local testing, leave the domain value blank.
'domain' => '',
I'm trying to continue the CakePHP session outside the application.
The CakePHP session config:
Configure::write('Session', array(
'checkAgent' => false,
'defaults' => 'cake',
'timeout' => 10080, // 1 week,
'ini' => array(
'session.cookie_httponly' => 1,
)
));
cakephp_webroot/test_session.php:
<?php
session_name("CAKEPHP");
session_start();
var_dump($_SESSION);
?>
test session.php should output the cake session, but it is not working. I've verified the cookie CAKEPHP is present.
You are using the cake defaults for session handling, they are not compatible with the PHP defaults (available as php for the defaults option).
The cake configuration uses a custom save path and enforces cookie usage.
https://github.com/cakephp/.../Datasource/CakeSession.php#L600-L612
// ...
'cake' => array(
'cookie' => 'CAKEPHP',
'timeout' => 240,
'ini' => array(
'session.use_trans_sid' => 0,
'url_rewriter.tags' => '',
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.cookie_path' => self::$path,
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
)
),
// ...
So either configure your external scripts session usage the same as the cake defaults, or use the php defaults instead, and control things via your PHP ini configuration.
See also
Cookbook > Development > Sessions > Built-in Session handlers & configuration
http://php.net/manual/en/session.configuration.php
I'm pretty new to Cakephp. I'd like my sessions data gets expired in 3 days. However, it seems like the expiration time is just a few hours, as when the user logs in, s/he will be logged out in a few hours.
Here is all the changes I have made in core.php:
I added timeout parameter:
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 4320
));
I checked most of the relevant questions and none of the solutions worked for me:
Changing 'timeout' to 'session.timeout', changing 4320 to '4320' and ,...
Thanks for you help in advance. :)
You can use below code for same:
Configure::write('Session', array(
'defaults' => 'php',
'timeout' => 30, // The session will timeout after 30 minutes of inactivity
'cookieTimeout' => 1440, // The session cookie will live for at most 24 hours, this does not effect session timeouts
'checkAgent' => false,
'autoRegenerate' => true, // causes the session expiration time to reset on each page load
));
Read more here