0

i am using magento 1.9 and i am try to set session out side magento file. my problem is session set but when i`m try to get session in view.phtml page it show result null.

this is my code:

set_time_limit(0);
ini_set('memory_limit', '-1');   
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::init();
$ponumber = "123456";
Mage::getSingleton('core/session')->setPonumber($ponumber); 
$getponumber = Mage::getSingleton('core/session')->getPonumber();
echo "ponumber->".$getponumber; // its print 123456

view.pthml

$ponumber= '';
$ponumber= Mage::getSingleton('core/session')->getPonumber();
echo "----->".$ponumber."<-----";

what am i doing wrong.

Any help or suggestion will be appreciated.

1 Answer 1

0

use these for session

Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$write = Mage::getSingleton ('core/resource')->getConnection('core_write');

reference

5
  • no change, same result(NULL). Sep 8, 2016 at 12:17
  • updated the answer and also added the reference. Sep 8, 2016 at 12:23
  • @DhavalDave i test your code and it's working after adding these. Sep 8, 2016 at 12:32
  • i try this in external magento file and view.phtml ,var_dump(Mage::getSingleton('core/session')); its show session external magento file but not in view.phtml Sep 8, 2016 at 13:05
  • @DhavalDave this code i use and it worked require_once 'app/Mage.php'; umask(0); Mage::app(); Mage::getSingleton('core/session', array('name' => 'frontend')); $write = Mage::getSingleton ('core/resource')->getConnection('core_write'); Sep 9, 2016 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.