The Curious Website Designer

Opencart - Unable To Login [Solved]

Posted by The Curious Website Designer | Posted on Fri 26 Jun 2020

Opencart - Unable To Login [Solved]

I recently had a problem logging in to an Opencart administrators control panel. I entered the username and password correctly, and although the url in the browser address bar changed to the correct dashboard url , the page displayed was still the login page.


This situation arose shortly after I started experiencing problems with session data not being retained.

The Solution

After wasting a couple of days trying to get to the bottom of the problem, it turned out that the solution was quite straightforward.

For some reason, the table 'oc_session' had been changed so that the column 'session_id' no longer had a primary index.

I have no idea how this happened, but to fix this, I simply had to import the following sql query:

DROP TABLE IF EXISTS `oc_session`;
CREATE TABLE `oc_session` (
  `session_id` varchar(32) NOT NULL,
  `data` text NOT NULL,
  `expire` datetime NOT NULL,
  PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

 

This deletes the existing session table and then re-creates it in the correct format..

If that doesn't fix the problem, another possible fix is to edit the file 'system/framework.php' and find:

setcookie($config->get('session_name'), $session->getId(), ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));

 

Replace with:

setcookie($config->get('session_name'), $session->getId(), time() + 60 * 60 * 24 * 7, ini_get('session.cookie_path'), ini_get('session.cookie_domain'));

 

This will set the cookie length to 1 week.

 

This article is mainly for me, because I have encountered the problem before and ended up reinstalling the whole site. But if it helps someone else, that's great too.

 

Tags: opencart, login, login problems