1

We need to show a page in case users come from a specific URL therefore we can achieve it with the following:

$refererSite = Mage::helper('core/http')->getHttpReferer();

however if user is not active for 30 minuets, the page should automatically be redirected to homepage.

We can create a session for the user by

Mage::getSingleton("core/session")

and give some time to it

$myValue = time();
Mage::getSingleton('core/session')->setLoggedTime($myValue);

I know the PHP way that is

header("refresh:1800;url=homepagexxx.php");

but is that what I should do?

Now one question is do I need to create a session at all or whoever comes already has a session and I need to set a time limit for it? if yes how to set a time limit and use it for refresh?

I am not sure how to tell that if session is not active for 30 minuets then redirect them to the homepage.

based on my experience even if you are not active, nothing will happen to the frontend webpage, Then I have to do something to force the page to refresh again.

0

1 Answer 1

0
+50

"The PHP-way" is NOT what you should do. You don't need to create a new session.

I leave out code for custom module and post just the relevant part. (if required let me know)

Add an observer for your cms page, that should redirect ...

app/code/local/My/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <My_Module>
            <version>0.0.1</version>
        </My_Module>
    </modules>
    <global>
        <models>
            <my_module>
                <class>My_Module_Model</class>
            </my_module>
        </models>
    </global>
    <frontend>
        <events>
            <!-- adjust full action name cms_index_index to your needs -->
            <controller_action_predispatch_cms_index_index>
                <observers>
                    <test>
                        <class>my_module/observer</class>
                        <method>test</method>
                    </test>
                </observers>
            </controller_action_predispatch_cms_index_index>
        </events>
    </frontend>
</config>

app/code/local/My/Module/Model/Observer.php

public function test(Varien_Event_Observer $observer)
{
    // check referer url code
    $refererSite = Mage::helper('core/http')->getHttpReferer();
    if ($refererSite === 'your_referer_url') {
        $observer = $observer->getEvent()
            ->getControllerAction()
            ->getResponse()
            ->setHeader('refresh', '1800; url=homepagexxx.php');
    }
}
3
  • I did not try it.
    – Nickool
    Commented Jul 24, 2017 at 19:53
  • @Nickool what was the bounty for if you've not tried? Spent several ages to find a something working :P
    – sv3n
    Commented Aug 7, 2017 at 21:50
  • we did it with javascript finally.I don't know lol we were looking for it a lot.
    – Nickool
    Commented Aug 14, 2017 at 22:45

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.