Cakephp randomly drops session - session

Recently I moved my cakephp site from a hosting service to an other. The page was working like a charm, but now I'm having the issue, that my sessions randomly drop.
I'm on a shared hosting service, so I changed cake's session defaults from php to cake, now my sessions are saved to my tmp/sessions folder. (but it wasn't working with php either)
Followed my session's way with Firebug:
When i log into the page, i have a Sessionid, and in the tmp/sessions folder i have the corresponding sess_{sessionid} file too.
After a few clicks on some pages (totally random) my sessionid changes and i'm "logged out".
The session file with which i've logged in, remained in the directory.
My session settings in core.php right now:
Configure::write('Session', array(
'defaults' => 'cake'
));
I'm using the 2.3.8 version of Cake.
Update:
Finally i found the problem thanks to Nick. I checked the Cakephp error files, and found out that i only got logged out, when i visited a page containing an element, which was not on the server ( eg a picture was missing). So i went to Firebug, and check what the Net tab says. On the new Host service i got a 404 Not Found response AND a new session id set in the response, whilst on the other servers i tested the page, i simply got a 404 Not Found. If i randomly generate links to not existing files like (domain/test.jpg) i get the same results.

Try these settings, in Firefox you can install the web develop extension, then you can view your cookie to see if it is all set correct.
Configure::write('Session', array(
'defaults' => 'php',
'cookie' => 'yourdomain',
'timeout' => 44640,
));

Check any components that you are using for whitespace (usually at the end of the file).
I came across this recently whilst helping a client with their existing CakePHP site, when logged in one particular page that called a component was killing $this->Session->read(‘Auth’).
There is a CakePHP shell that you can use to find whitespace.

Related

Session not persisting on shared hosting - Laravel 4.2.17

I have a problem with the sessions on the shared hosting.
I developed an app on a local server (XAMPP) and it works great (sessions, auth etc). The problems have appeared when I moved the app on a shared hosting.
I realized that the sessions are not persisting from a page to another or from AJAX files to another page and the Authentication does not work either .
The only session that persists is the _token which has a different value after every refresh of the page.
I have the following configuration in the session.php file:
'driver' => 'database',
'lifetime' => 120,
'expire_on_close' => false,
'lottery' => array(2, 100),
'path' => '/',
'domain' => null
First, I used file driver and I had the same problem, and now I used the database.
Both file and database work on the local server but on the shared hosting they do not.
I tried all the solutions found on the forum but still I have the same problem.
I think the problem is at the session domain setting because when I change the value from null to other string on my local server, I have the same problem that I have encountered online.
Can you help me, please!
Thanks, Mirel
I fixed the problem. In my case the error because I have added a php closed tag ?> in the end of the included files. So removing this tag will bring the application back to normal behavior.

Can't login into magento 1.8.1.0 on localhost on wamp server using correct username and password

I have fresh installed magento 1.8.1.0 on localhost with wamp server. Everything has been installed correctly but when i login into the login page with correct username and password it opens the same login page and not get into dashboard page.
I had read a lot of threads saying to make changes in variens.php by opening Go to app/code/core/Mage/Core/Model/Session/Abstract/Varien.php file within your magento directory.
When i open app/code/core/ i can't find mage folder in core folder.
Please help how can i fix it?
thank you
kamaldeep singh
I don't have the folder mage inside the app/code/core. But i read some thread and made changes using 127.0.0.1/mymagento/index.php/admin in address bar by editing my C:/Windows/system32/drivers/etc/hosts it went to dashboard page
And appears error on dashboard
Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\wamp\www\mymagento\lib\internal\Magento\Framework\Code\Reader\ClassReader.php on line 77
i checked classReader.php on line 77 but there is no line related to nesting level to edit.
When i refresh the dashboard page it opens the login page. when i try to login with correct username and password it opens the same login page and no error like invalid username or password.
If you don't have the Mage folder inside app/code/core your website should not work at all. That folder is essential to run Magento. Check again.
About your problem, do you get any error (wrong username, password, etc.)?
Do you mean a customer cant login, or you cant log into the backend, there is an existing issue with customer login depending on the version of magento you might be using.
find : app/design/frontend/(themepackage(/(theme)/template/customer/form/login.phtml
under
<ul class=”form-list”>
paste in
<input type=”hidden” name=”form_key” value=”<? echo Mage::getSingleton(‘core/session’)->getFormKey(); ?>” />
And in app/design/frontend/(themepackage(/(theme)/template/persistent/customer/form/login.phtml
Apply the same changes.
Clear cache.
Customers should then be able to login.
Resource
Does it says that username or password is wrong or only refreshes the page without any error messages? If there are no errors then try to delete cookies for your host and then login again. Usually it helps.
Are you using chrome? If so, try Firefox. Another option might be to use 127.0.0.1/... instead of localhost/...
In your magento installed folder, go to app/code/core/Mage/Core/Model/Session/Abstract/Varien.php And comment out the lines 96 to 112 in v1.9. Lines may differ due to version. Look for lines that looks like this below:
// session cookie params
/** $cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath(),
'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->getHttponly()
);
if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}
**/
Have fun :)
If you have this problem on non FireFox browser(s), use FireFox to execute this action below and try login in with your non FireFox browser(s) again to confirm. I had this issue with Chrome.
Go to System > Configuration > Web > Session Cookie Management. And change Use HTTP Only from YES to NO.

session not working on server in cakephp

I am working in cakephp. My all code working fine but when I upload the code on server then session functionality does not work.
There are no error on server.Just session does not write or read.
I am using go Daddy hosting.
my core file settings are:-
Configure::write('Session', array(
'defaults' => 'cake'
));
// Session cookie now persists across all subdomains
ini_set('session.cookie_domain', env('HTTP_BASE'));
and temp folder is writable and session id and other values in session are shown in temp folder file.but session still not working.
I got my answer that there is a space problem after php closing tag in my one cotroller so just removed that space like
(?> ) to (?>)

session timeout forever cakephp

i am working on a Cakephp 2.x ... i am using auth component ... the problem write now is that the session automatically expires after some minutes.. i mean if the user does nothing then CakePHP logs them out after some period...i want to make the session time forever unless he click the logout button ..i dont know how to to do this .. any help would be greatly appreciated
Here's my config code:
Configure::write('Session', array(
'defaults' => 'php'
));
I think the problem is that you're using the default php sessions and they are configured (in php.ini) to expire sooner than you want to. See.
If you want your logins to live forever it's probably better to use cookie based login. See this plugin for instance.

localhost to 127.0.0.1 as default

I am trying to use Magento on a localhost, but when I try and log in to the admin area the screen just refreshes.
In the address bar it was localhost/magento/.......(etc). When I changed it to 127.0.0.1/magento/.......(etc) it allowed me in. When I click on one of the buttons in the admin area it goes back to localhost/magento/......(etc) and I am once again faced with the login page.
How and where do I alter the setting the settings so the 127.0.0.1 is used as default rather than localhost.
Finally after seven hours of playing about with suggestions and re-installing I have fixed it, for those with the same problem i will share what I did.
I am using Magento 1.7.0.2. Apparently there is an issue regarding cookies when you install Magento on windows as it was designed for linux system. So you need to sort the cookie issue. To do this open your Magento folder and go to app>code>core>mage>core>model>session>abstract varien.php at lines 85-92:
// session cookie params
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath()
//'domain' => $cookie->getConfigDomain(),
//'secure' => $cookie->isSecure(),
//'httponly' => $cookie->getHttponly()
);
change the code to this.
Apparently there are other issues such as php curl, I did not come across these but the following tut:
http://ecommercedeveloper.com/articles/1419-tutorial-avoid-two-problems-installing-magento-on-a-localhost/
covers it. Also that's where I got the information from, however the code in the version I'm using is slightly different from that version.
If you want to change loaclhost to 12.0.0.1 do following.
If you have database access go to "*core_config_data*" table and there change "web/unsecure/base_url" and "web/secure/base_url" to 127.0.0.1 instead of localhost.
Otherwise you can use the solution provided by tony09uk.
on OS X I found a simpler way - I am using MAMP running 127.0.0.1:8888, the default for MAMP installs.
Just set your /app/etc/config.xml line that says localhost to 127.0.0.1
delete var cache and session contents
clear cookies in browser
this now lets me login to the dashboard from the admin login screen.
If you have database acces open table: core_config_data
Do a search for: SELECT * FROM core_config_data WHERE path LIKE '%cookie%'
change: cookie_domain & cookie_path to = ""
(empty string).
Login once again to the admin panel. fixed!

Resources