doubo4824 2011-02-12 23:28
浏览 43
已采纳

Magento和跨商店同步会话的最佳方式

I am syncing sessions between two different domains for Magento using a token passing technique with a remote iframe or img. I am about to implement it into Magento and was looking for some pointers.

I will have to do two things:

  1. Every 5 mins, output an iframe or img with a remote SRC attribute for the second domain.
    • Q. Where is the best place to implement this? In the past I did storewide actions by overriding the renderLayout() method in Magento. Should I just do it by appended a block to the end of the page load? If I use a block, is it still keeping MVC?
  2. I need to sync the session on the other domain when the script is called. I need to set the same cookie that Magento would set, that links to that session for the user.
    • Thinking about this, I think I am going to have to load Mage::app or whatever the call is that loads the Magento environment.
    • Q. Is there a lighter way of doing this?

Just for better understanding of what I am doing, here is a quick description of the flow.

  1. User goes to Site A. If its time to sync the sessions, an IMG or IFRAME is outputted with SRC pointing to site-b.com/sessionSyncer?token=SHA1TOKEN
  2. sessinSyncer validates the token and if so, creates a session and sends the cookie to the browser for the session. This should happen in a Magento manner

I am aware that Magento has the ability to pass session through the URL and generates the links to do so, but this is inadequate because the user must only switch sites using those special urls, plus the URL becomes ugly.

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • douhoushou8385 2011-02-13 14:22
    关注

    Overriding renderLayout is overkill. Instead create a block that outputs your img tag and include it in the base theme, perhaps for the area before_body_end, that will safely place it on all pages.

    Inventing your own token is also overkill since Magento is using the PHP session identifier and places it automatically for foreign domains. Your custom block might generate the URL with this:

    $this->getUrl('OTHER/STORE/PATH', array('_store' => 'YOUR_STORE_CODE'))
    

    If you think your script is going to need Mage::app() then you might as well use a controller which is a similar effort. On encountering a SID value the session will be updated behind the scenes, cookies set etc.

    It using an iframe it doesn't need to output anything and if a small image can be static like this:

    print "GIF89a\1\0\1\0\x80\0\0\xff\xff\xff\xff\xff\xff!\xf9\4\1
    \0\1\0,\0\0\0\0\1\0\1\0\0\2\2L\1\0;";
    

    P.S.
    When creating the URL of the foreign store without an SID use the _nosid parameter to force a clean URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?