access session data of opencart through php file

陌路散爱 提交于 2019-12-24 22:26:19

问题


I am new to opencart. I have my basic php code at http://localhost/testphp

and my opencart is installed at http://localhost/opencart. What I want to do is that in testphp, I have a page in which I want to check that if any user is logged in or not at opencart.

If it is logged in then I want to perform x function

and It not logged in then want to perform y function

I have tried to logged in to opencart and tried to print_r($_SESSION) in testphp. It is returning blank. How can I perform this ? Please help me


回答1:


If you are using localhost then you can try this. or same hosting account or cpanel

Go to catalog/controller/common/header.php

Before "public function index() {" Add this code

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

You Have to Print Array in http://localhost/testphp Code :

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

Your Output Will be

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

        )

)


来源:https://stackoverflow.com/questions/47362992/access-session-data-of-opencart-through-php-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!