本文介绍了通过php文件访问opencart的会话数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Opencart的新手.我在http://localhost/testphp

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

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

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.

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

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

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

and It not logged in then want to perform y function

我已经尝试登录到opencart,并尝试在testphp中进入print_r($_SESSION). 它返回空白.我该如何执行呢?请帮助我

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

推荐答案

如果您使用的是localhost,则可以尝试此操作.或相同的托管帐户或cpanel

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

转到目录/控制器/common/header.php

公共功能index(){" 之前 添加此代码

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

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

您必须在http://localhost/testphp中打印阵列代码:

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

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

        )

)

这篇关于通过php文件访问opencart的会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:12