Cakephp session cookie name using wrong - session

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');

Related

Lumen/Laravel session for specific route

I am trying to get working Lumen session but only for a specific route, since on other I don't need it.
All I find is to enable middlewhere like
$app->middleware([
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
]);
(source https://stackoverflow.com/a/32635502/1861519)
But this will do a global session setting. But I needed it only as sad on specific route.
All app level middleware goes here
$app->middleware([
\Illuminate\Cookie\Middleware\EncryptCookies,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse ]);
Custom middleware that need session
$app->routeMiddleware([
'session' => \Illuminate\Session\Middleware\StartSession]);
Now add it in route
$app->get('/protected', ['middleware' => 'session', 'uses' => 'ProtectedController#index'])
You can try this when use session on specific routes:
$session = $request->session();
$session->put('foo', 'bar');
echo $session->get('foo');
$session->save();
save() will persist the session file for you.

Not getting cookie value in codeigniter

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' => '',

CakePHP continue session outside cake

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

cakephp session.cooke_lifetime doesn't work

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,
));

how to get and use codeigniter cookies?

I am trying to use codeigniter cookies so that i can bookmark some topic , i don't know how to get cookies vale and use it to display bookmarked item in the user browser , it doesn't work when i try to display cokies value using print_r(); please help how to proceed. Thanks
function index(){
$this->load->helper('cookie');
$data['title'] = 'some bookmark';
$cookie = array(
'name' =>'mycookie',
'value' => 'some val',
'expire' => '86500',
'domain' => '.localhost',
'path' => '/',
'prefix' => 'something_'
);
set_cookie($cookie);
$this->load->view('bookmark', $data);
}
Browsers have trouble dealing with localhost (or .localhost) as the domain for cookie storage - they expect a domain to have at least two dots. Try setting the domain to FALSE (or don't set it) while testing.
If that still doesn't work, can you show us how you're retrieving the cookie data?

Resources