无法在外部文件中获取magento会话

时间:2016-03-01 05:10:17

标签: php magento session

我试图在公共html / root目录中的一个名为testsession.php的文件中获取magento之外的magento会话。 我试图使用以下代码来获取用户数据。

    <?php
// Include Magento application
require_once ( "app/Mage.php" );//path to your magento Mage.php file
umask(0);

// Initialize Magento
Mage::app();

// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "frontend"));

$session = Mage::getSingleton("customer/session");

if($session->isLoggedIn())
{
    echo "Logged in";
}else{
    echo "Not logged in";
}

但我得到了这个结果

 Cannot send headers; headers already sent in /home/name/public_html/forum/global.php(29) : eval()'d code, line 5 on
 line 323 in
 /home/name/public_html/lib/Zend/Controller/Response/Abstract.php
 0 /home/name/public_html/lib/Zend/Controller/Response/Abstract.php(115):
 Zend_Controller_Response_Abstract->canSendHeaders(true)
 1 /home/name/public_html/app/code/core/Mage/Core/Model/App.php(1265): Zend_Controller_Response_Abstract->setHeader('Content-Type',
 'text/html; char...')
2 /home/name/public_html/app/code/core/Mage/Core/Model/Cookie.php(93):
Mage_Core_Model_App->getResponse()
3 /home/name/public_html/app/code/core/Mage/Core/Model/Cookie.php(209):
 Mage_Core_Model_Cookie->_getResponse()
4 /home/name/public_html/app/code/core/Mage/Core/Model/Cookie.php(260):
 Mage_Core_Model_Cookie->set('frontend', '5cccec0d46ce83d...', NULL,
NULL, NULL, NULL, NULL)
5 /home/name/public_html/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php(163):
Mage_Core_Model_Cookie->renew('frontend')
6 /home/name/public_html/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php(222):
 Mage_Core_Model_Session_Abstract_Varien->start('frontend')
7 /home/name/public_html/app/code/core/Mage/Core/Model/Session/Abstract.php(84):
Mage_Core_Model_Session_Abstract_Varien->init('core', 'frontend')
8 /home/name/public_html/app/code/core/Mage/Core/Model/Session.php(42):
Mage_Core_Model_Session_Abstract->init('core', 'frontend')
9 /home/name/public_html/app/code/core/Mage/Core/Model/Config.php(1348):
Mage_Core_Model_Session->__construct(Array)
10 /home/name/public_html/app/Mage.php(467): Mage_Core_Model_Config-getModelInstance('core/session', Array)
11 /home/name/public_html/app/Mage.php(481): Mage::getModel('core/session', Array)
12 /home/name/public_html/forum/global.php(29) : eval()'d code(11): Mage::getSingleton('core/session', Array)
13 /home/name/public_html/forum/global.php(29): eval()
14 /home/name/public_html/forum/forum.php(67): require_once('/home/name/...')
15 {main}

有谁知道我怎么能解决这个错误? 感谢

1 个答案:

答案 0 :(得分:0)

试试这段代码。

library(xts)
library(ggplot2)
library(reshape2)

set.seed(42)
timevalues = "20150101 0000/20150110 2359"
timesequence <- timeBasedSeq(timevalues)
min_data <- xts(rnorm(14400),timesequence)

ts_data <- ts(as.numeric(min_data), frequency = 1440)
out <- stl(ts_data, s.window = "per")
time.series <- as.data.frame(cbind(ts_data, out$time.series))
colnames(time.series) <- c("Data", "Seasonal", "Trend", "Remainder")
time.series$Date <- timesequence
time.series <- melt(time.series, 'Date')

ggplot(time.series, aes(x=Date, y=value)) + 
  geom_line() +
  facet_free(variable~.)

希望这能帮到你!