douqiang1910 2014-10-21 10:34
浏览 43
已采纳

如何在我的网站上使用prestashop登录系统与其他网页(店外)?

Dear friends I have installed prestashop on my existing website.My current website has a login system that I have already built.

Because of installing prestashop for my system,I thought to change my existing login to prestashop login.

As for the prestashop documentation,to access prestashop cookie outside prestashop,I made a test page to retrieve cookie data as follows,

include_once('path_to_prestashop/config/config.inc.php');
include_once('path_to_prestashop/config/settings.inc.php');
include_once('path_to_prestashop/classes/Cookie.php');
$cookie = new Cookie('ps');
print_r($cookie);

But this is not working and browser says

It contains redirect loop.

I tried to disable SEO friendly url and cannonical url to no-direct as some posts suggested.

Now if I go to the test page it redirects to the prestashop index page rather displaying cookie data.

What should I do to overcome this problem?

Thank you.

  • 写回答

1条回答 默认 最新

  • duanji6997 2014-10-22 20:09
    关注

    When you include config/config.inc.php PrestaShop redirects to the shop domain.

    The following code is causing this behavior in classes/shop/Shop.php:

    $shop = new Shop($id_shop);
    if (!Validate::isLoadedObject($shop) || !$shop->active)
    {
      // No shop found ... too bad, let's redirect to default shop
      $default_shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
    
      // Hmm there is something really bad in your Prestashop !
      if (!Validate::isLoadedObject($default_shop))
        throw new PrestaShopException('Shop not found');
    
      $params = $_GET;
      unset($params['id_shop']);
      $url = $default_shop->domain;
      if (!Configuration::get('PS_REWRITING_SETTINGS'))
        $url .= $default_shop->getBaseURI().'index.php?'.http_build_query($params);
      else
      {
        // Catch url with subdomain "www"
        if (strpos($url, 'www.') === 0 && 'www.'.$_SERVER['HTTP_HOST'] === $url || $_SERVER['HTTP_HOST'] === 'www.'.$url)
          $url .= $_SERVER['REQUEST_URI'];
        else
          $url .= $default_shop->getBaseURI();
    
        if (count($params))
          $url .= '?'.http_build_query($params);
      }
      $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302';
      header('HTTP/1.0 '.$redirect_type.' Moved');
      header('location: http://'.$url);
      exit;
    }
    

    You could override the Shop class to disable the redirect for your script.

    To do this first define PS_DISABLE_SHOP_REDIRECT constant before you include config/config.inc.php:

    define('PS_DISABLE_SHOP_REDIRECT', true);
    

    Then paste the following before the previous code in the overridden class:

    if (defined('PS_DISABLE_SHOP_REDIRECT')) {
      $id_shop = Configuration::get('PS_SHOP_DEFAULT');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 在虚拟机环境下完成以下,要求截图!
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见