英文:
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?
<?php echo $firstname; ?>
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['mysessionvariable'] = $this->session;
You can restrict the available data to the sessionID only using the code below:
$data['mysessionvariable'] = $this->session->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['session_id'];
or echo $mysessionvariable;
View file: public_html\catalog\view\theme\default\template\product\product.tpl
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论