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

时间:2017-11-18 05:52:04

标签: php session opencart opencart2.x opencart2.3

我是opencart的新手。我在http://localhost/testphp

上有我的基本php代码

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

如果已登录,那么我想执行x功能

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

我尝试登录opencart并尝试在testphp中print_r($_SESSION)。  它返回空白。我怎么能这样做?请帮帮我

1 个答案:

答案 0 :(得分:2)

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

转到目录/ controller / common / header.php

"公共职能指数(){" 之前   添加此代码

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] => 
                )

        )

)