Read Cookie PHPSESSID in opencart:2.3.0.2 读取 opencart:2.3.0.2 中的 PHPSESSID Cookie

huangapple go评论60阅读模式
英文:

Read Cookie PHPSESSID in opencart:2.3.0.2

问题

I want to use an opencart database for another website, so users don't need to register their details again.

For example: I sell Clothes (unStitched) on opencart and I also give services for stitching them. Opencart doesn't have a module to do this, so I want to redirect users to another website and there I want to read the user details for further processing.

How can I read PHPSESSID cookie? How does opencart read firstname on edit profile forms?

<?php echo $firstname; ?>

Thanks in advance.

英文:

I want to use an opencart database for another website, so users don't need to register their details again.

For example: I sell Clothes (unStitched) on opencart and I also give services for stitching them. Opencart doesn't have a module to do this, so I want to redirect users to another website and there I want to read the user details for further processing.

How can I read PHPSESSID cookie? How does opencart read firstname on edit profile forms?

&lt;?php echo $firstname; ?&gt;

Thanks in advance.

答案1

得分: 1

为了在Opencart视图中处理会话数据,您需要在控制器中添加一些代码。首先,我们需要在控制器中添加一个项到$data数组中,该数组用于将变量传递给视图:

假设您想在产品视图中显示此链接,您需要编辑产品控制器的index操作。

控制器文件:public_html\catalog\controller\product\product.php

找到以下行:

if ($product_info) {

在大括号内添加以下文本:

$data['mysessionvariable'] = $this->session;

您可以使用以下代码将可用数据限制为仅包括sessionID:

$data['mysessionvariable'] = $this->session->getId();

现在,视图可以访问相关的PHP会话数据,您可以在视图中简单地引用会话变量,无论在何处需要。例如,echo $mysessionvariable['session_id'];echo $mysessionvariable;

视图文件:public_html\catalog\view\theme\default\template\product\product.tpl

英文:

In order to work with the Session data in an Opencart view, you will need to add some code to the controller. First we need to add an item in the $data array that the controller uses to pass variables to the view:

Assuming you want to show this link in a product view, you will need to edit the product controller's index action.

Controller file: public_html\catalog\controller\product\product.php

Find this line:

if ($product_info) {

Add the text inside the brace:

    $data[&#39;mysessionvariable&#39;] = $this-&gt;session;

You can restrict the available data to the sessionID only using the code below:

    $data[&#39;mysessionvariable&#39;] = $this-&gt;session-&gt;getId();

Now the relevant PHP Session data is available to the view, you can simply reference the session variable in the view wherever your need to. e.g. echo $mysessionvariable[&#39;session_id&#39;]; or echo $mysessionvariable;

View file: public_html\catalog\view\theme\default\template\product\product.tpl

huangapple
  • 本文由 发表于 2020年1月6日 22:05:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定