403错误背后的常见原因 [英] Common reasons behind 403 errors

查看:129
本文介绍了403错误背后的常见原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我正确写的两个函数。

Below are two functions that I'm positive are written correctly.

问题是,有时,当我的会话没有超时,但AJAX请求返回403错误(也发生与一些其他函数没有任何模式)。

Problem is, that there are times, when my Session does not time out, but the AJAX request returns 403 error (also happens with some other functions without any pattern).

堆栈溢出充满问题要求帮助这个问题,但我没有找到任何真正好的答案:

Stack overflow is filled with questions asking for help with this problem, but I did not find any really good answers:

  • Redirection + 403 error
  • Http 403 - Forbidden error
  • 403 Forbidden Error
  • getting 403 forbidden in ajax
  • etc

问题:


  1. 如何通过代码导致403错误?

  2. 如果我有多个异步AJAX请求同时运行,可能会导致403错误? (我一次做几个(最多5)ajax请求)

  3. 如果我想以相对路径的形式调用AJAX请求,我必须在.htaccess中设置一些目录列表/ action>而不是relative_pat / action.php?

  4. 403可能是由于我的会话到期而导致的。

  1. How can you cause a 403 error by code?
  2. If I have multiple asynchronous AJAX requests running at the same time, can it cause a 403 error? ( I do fire several (max 5) ajax requests at one time )
  3. Do I have to set something about directory listing in .htaccess if I want to call AJAX requests in the form of relative_path/action instead of relative_pat/action.php?
  4. 403 can be caused, by my Session expiring, right?

AJAX:

    var root = "/test_tool";    

    function isLoggedIn()
    {
        // return if the user is in the sign in window
        if ( window.location == "http://localhost" + root +"/" )
        {
            return;
        }

        var output = "";
        $.ajax (
        {
            url: root + "/users/isLoggedIn",
            context: document.body,
            async: true
        } ).done( function( result ) 
        {
            output = result;
            if ( output == "" )
            {
                alert( " You have been logged out. " );
                window.location = "http://localhost" + root +"/";
            }
        }); 
    }

(CAKE)PHP:

public function isLoggedIn() 
{
    $this->autoRender = false;
    return ( $this->Auth->user('username') != null );
}


推荐答案

通过代码获取403。请从CakePHP文档中检查此内容( http ://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#handling-unauthenticated-requests ):

1.It is possible to get a 403 via code. Check this out from the CakePHP docs (http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#handling-unauthenticated-requests):

如果authenticator返回null,AuthComponent会将用户重定向到登录操作。如果它是一个ajax请求,并且指定了AuthComponent :: $ ajaxLogin,那么将返回该元素。否则会返回403 http状态代码。

2.多个Ajax调用不应该是403错误的原因。

2.Multiple Ajax calls shouldn't be the causing factor of a 403 error.

3.标准路由由CakePHP本身处理。如果你需要一些不同的路由,你应该在routes.php中配置。我会说使用.htaccess只是一个真正极端的路由需求,应该是最后的手段。

3.The standard routing is handled by CakePHP itself. If you need some different routing, you should configure this in routes.php. I would say using .htaccess is only for a really extreme routing need and should be a last resort.

4.这可能是一个原因,因为你不再登录,从而获得Auth 403s(参见答案#1)。

4.Yes that could be a cause, since you would no longer be logged in, thus get Auth 403s (see answer #1).

这篇关于403错误背后的常见原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆