0

Creating a custom session in a store view's index.php in a subdirectory of the main magento installion.

The code I added is as follows:

require_once $mageFilename;
Mage::init();
Mage::getSingleton('core/session')->setRefer("access");
$refer = Mage::getSingleton('core/session')->getRefer();
echo $refer;

I added the code under require_once $mageFilename; in index.php otherwise I would get Mage errors.

I want to use the session for something more complex but I can't get even this basic code to work!

This causes the mantenance page to display for some reason with access echod at the top of the page. Maintenance displays even when I take out the code which displays the maintenence page inside the index.php.

Any advice is greatly appreciated!

EDIT1:

When moving my code to bottom of file:

$mageRunCode = 'mystore';
$mageRunType = 'store';
Mage::run($mageRunCode, $mageRunType);
Mage::getSingleton('core/session')->setRefer("denied");
$refer = Mage::getSingleton('core/session')->getRefer();
if($refer == "access") {
}else{
    include_once 'XXXXXXXXX/503.php';
    exit;
}

This makes my store view appear and then stacks the maintenance page below it!

1 Answer 1

0

Try putting it at the bottom of the file. It worked like this for me without the first two lines

Mage::getSingleton('core/session')->setRefer("access");
$refer = Mage::getSingleton('core/session')->getRefer();
echo $refer;

Re: new problem

Try copying line 64 -

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
} 

to after

require_once $mageFilename;

and add in the check for the session like -

$maintenanceFile = 'path to file';
require_once $mageFilename;
if (file_exists($maintenanceFile) && $refer != 'access') {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
} 

Fyi - using regular php session variables might be more suitable if you need to do much with them in index.php. The reasons for the errors is because of Mage not being loaded when you try to use it.

9
  • Thanks for the reply, when adding this at the bottom I simply get no echo at all Commented Apr 15, 2015 at 11:52
  • Try searching the page for 'access' using ctrl+f (windows) or cmd+f (mac). I couldn't see it straight away Commented Apr 15, 2015 at 11:53
  • Ok thanks this worked however created another problem! SEE POST The code is below where I pull in the store view. So when session "denied" the user should see maintenance. As the store view is loaded first it shows the store view stacked on top of maintenance! Commented Apr 15, 2015 at 12:01
  • well feel free to ask but if you could select my answer as correct and upvote if it's fixed the problem in the question i'd appreciate it Commented Apr 15, 2015 at 12:04
  • If i put the code above the store view code I get the error: Fatal error: Call to a member function getModelInstance() on a non-object in /PATH/app/Mage.php on line 463 Commented Apr 15, 2015 at 12:05

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.