通过 php 文件访问 opencart 的会话数据

access session data of opencart through php file

我是 opencart 的新手。我的基本 php 代码位于 http://localhost/testphp

我的 opencart 安装在 http://localhost/opencart。我想要做的是,在 testphp 中,我有一个页面,其中我 want to check that if any user is logged in or not at opencart.

如果登录了那么我要执行x函数

并且它没有登录然后想执行 y 功能

我已经尝试登录 opencart 并尝试 print_r($_SESSION) 测试 php。 它返回空白。我该如何执行此操作?请帮助我

如果您使用的是本地主机,那么您可以试试这个。 或相同的托管帐户或 cpanel

转到catalog/controller/common/header。php

之前"public function index() {" 添加此代码

class ControllerCommonHeader extends Controller {
    public function index() {    
             session_start();
             $_SESSION['opencart'] = $this->session->data;

你必须在 http://localhost/testphp 中打印数组 代码:

<?php
session_start();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?>

您的输出将是

Array
(
    [opencart] => Array
        (
            [language] => en-gb
            [currency] => USD
            [customer_id] => 2
            [shipping_address] => Array
                (
                    [address_id] => 2
                    [firstname] => Prashant
                    [lastname] => Bhagat
                    [company] => 
                    [address_1] => Surat
                    [address_2] => 
                    [postcode] => 395003
                    [city] => Surat
                    [zone_id] => 1485
                    [zone] => Gujarat
                    [zone_code] => GU
                    [country_id] => 99
                    [country] => India
                    [iso_code_2] => IN
                    [iso_code_3] => IND
                    [address_format] => 
                    [custom_field] => 
                )

        )

)