Andrew Hayes
Andrew Hayes

Reputation: 11

Issues with OpenCart cookies

I have moved my OpenCart store to a different host (by restoring CPanel backups - home directory, MySQL database, email forwarders), changed my config.php accordingly, and everything seemed to work normally on the front-end. However, I am experiencing some major issues that affect crucial parts of the store.

First off, whenever I try to log in to the admin panel I receive the following message (as a javascript 'alert' popup):

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
OK

Followed by the raw HTML code of the admin login page:

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="UTF-8" />
<title>Administration</title>
<base href="https://[MY STORE URL]/admin/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
... etc

When I am trying to move around between different sections of the admin control panel I am constatly getting logged out, and receive the same error upon logging back in.

Moreover, user login and checkout are also broken. I can add products to the shopping cart as a guest and proceed to the checkout page, everything appears to be working, however when I put in registration details and press the checkout button, nothing happens (it is supposed to be redirecting to PayPal, as it does on my old host). I am using Journal 2 as my theme, which uses javascript to handle such buttons, so it shows no errors at all.

When I log in to my user account (as a customer) it only works for one page. If I move anywhere else on the website my account is getting logged out.

Based on the fact that I am unable to stay logged in my presumption is that the aforementioned issues have something to do with cookies.

Is there any way to resolve this?

I use OpenCart 2.3.0.2, and MariaDB 10.2.25-MariaDB-cll-lve - MariaDB Server (it differs from the initial host, which shows MySQL 5.6.45-cll-lve - MySQL Community Server (GPL)).

Upvotes: 0

Views: 449

Answers (1)

Konstantinos
Konstantinos

Reputation: 417

The error you get with alert:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

is from an ajax request that is made every-time you login / navigate inside the admin panel.

Steps to find the issue:

  1. Before you login in the admin panel, right click in the browser and click "inspect element".
  2. Choose tab "Network"
  3. Login into the admin panel with your credentials.
  4. Click ok at the alert of the error and then check into the network tab for the XHR (ajax) request made.
  5. In the response sub-tab you will probably find a PHP exception. Find the cause of the error.

Important:

When a PHP error occurs while ajax request is made, the user token is "lost" so that's why you get logged out. It's not cookie related.

Hope the above helped you.

Upvotes: 1

Related Questions