0

I'm currently using X-Cart and have some employees (each has an X-Cart administration account). I also develop some custom PHP webpages (not X-Cart modules) which require my employees to login before they can access those webpages. I want my employees to use their existing X-Cart accounts to login.

For example, whenever my employees access custom webpages, if they're already logged in to X-Cart, they should be fine. If not, they should be redirected to X-Cart's admin login page.

My question is: How can my PHP scripts check if users are already logged in to X-Cart? I tried to include auth.php but I got the error message "Can not initiate application! Please check configuration."

Thanks a lot!

4

1 回答 1

0

创建安全的管理页面非常简单:

  1. 在 ROOT/admin/my_new_app.php 中创建新页面
  2. 开始你的代码:

    /* My new App is secure */
    require './auth.php';
    require $xcart_dir.'/include/security.php';
    
    /* Put your App code in here... */
    
    
    /* You may (and you should) end with assigning main template as:
    $my_main = 'my_new_app';
    $location[] = array('New App!', '/admin/my_new_app.php');
    
    
    /* But then you need to go and edit YOUR_SKIN/single/home.tpl and add this:
    
    {elseif $main eq "my_new_app"}
    {include file="admin/my_new_app.tpl"}
    
    and you need to create your template file: admin/my_new_app.tpl 
    */
    

就是这样。如果您不是管理员,您将被重定向到登录页面(管理区域)。

这里有一个重要的注意事项:如果页面上没有真实的表单,您不能在应用程序中使用 post 变量。您必须创建一个表单,然后 xcart 将创建一个隐藏的输入字段_formid(并且它将具有一些散列值,例如:) 20b8e92504d1908bb1e3a264b9169f1e。一旦你有了它,你就可以使用 AJAX 和发布变量,每次都包括_formid它的值。

我告诉你这个的原因是你收到的奇怪信息:Can not initiate application! Please check configuration。它不是来自 x-Cart,我的猜测是:您的应用尝试发布,但没有得到响应(缺少_formid)。

于 2015-01-29T13:49:25.033 回答