本文介紹了來自外部頁面的 Magento 會話(同域)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要檢查用戶是否已注冊并獲取您的信息,但都在同一個域內但在 Magento 結構之外的文件中:/mymagento/islogged.php
I need to check that a user is registered and get your information, but all in a file within the same domain but outside the structure of Magento: /mymagento/islogged.php
require_once ('app/Mage.php');
Mage::app();
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
$sessionCustomer = Mage::getSingleton("customer/session");
if($sessionCustomer->isLoggedIn()) {
$customer = $sessionCustomer->getCustomer();
$telefono = $customer->getTelefonoMovil();
} else {
header('Location: '.ROOT.'customer/account/login/');
}
但是它不起作用,找不到會話.我已查看以下主題:
But it does not work, can not find the session. I have reviewed the following threads:
- Magento 會話在外部頁面(同域)中不起作用
- Magento 客戶/會話不工作
- 如何在外部創建 Magento 會話Magento?
- 如何從 Magento 外部訪問 Magento 用戶的會話?
- 檢查外部頁面上的 Magento 登錄
- 在另一個頁面中獲取 magento 會話變量
推薦答案
最后我是這樣做的:
require_once ('app/Mage.php');
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
// Obtain the general session and search for an item called 'customer_id'
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));
if(isset($coreSession['visitor_data']['customer_id'])){
$customerId = $coreSession['visitor_data']['customer_id'];
} else {
header('Location: '.ROOT.'customer/account/login/');
}
// Load the user session.
Mage::getSingleton('customer/session')->loginById($customerId);
$customerSession = Mage::getSingleton("customer/session");
// We verified that created successfully (not required)
if(!$customerSession->isLoggedIn()) {
header('Location: '.ROOT.'customer/account/login/');
}
// Load customer
$customer = $customerSession->getCustomer();
// We get cell phone
$telefono = $customer->getTelefonoMovil();
這篇關于來自外部頁面的 Magento 會話(同域)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!