【问题标题】:Redirection on codeigniter route在 codeigniter 路由上重定向
【发布时间】:2018-08-08 13:17:26
【问题描述】:

我已经在 codeigniter 上设置了这条路线:

$route['usuario/dar-baja']['POST'] = 'Private/Clients/dropClient';

但是当我尝试以这种方式提出请求时:

$('#confirmed-drop').click(function(){
    var reason=$("#motivos_baja option:selected").val();
    $.post("{{ base_url }}usuario/dar-baja",{reason:reason});
});

请求返回 302 重定向,并发生对同一 URL 的新 GET 请求,因为处理 GET 请求的路由不存在,因此我收到 404 page not found 错误。

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    很可能来自 CSRF,Codeigniter 使用它来确保用户无法重新提交表单。

    使用config.php 中的这些步骤禁用此链接上的 CSRF

    $csrf_ignore = [
    
        'usuario/dar-baja'
    ];
    
    $is_csrf_condition_met = true;
    
    foreach($csrf_ignore as $ci){
    
        if (strpos($_SERVER["REQUEST_URI"], $ci) !== FALSE) {
    
            $is_csrf_condition_met = false;
            break;
        }
    }
    
    $config['csrf_protection'] = $is_csrf_condition_met;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多