Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在CodeIgniter中执行POST请求_Php_.htaccess_Codeigniter - Fatal编程技术网

Php 无法在CodeIgniter中执行POST请求

Php 无法在CodeIgniter中执行POST请求,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我在页面中有一个表单,它使用CodeIgniter框架将用户数据上传到我的在线服务器上。我可以使用HTTPS协议正常访问表单页面,但是当我尝试使用POST提交表单时,我收到了一个403禁止:您没有访问此服务器的权限。错误。可能是什么问题 .htaccess文件: RewriteEngine On RewriteCond $1 !^(index\.php|resources|images|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f Rewrit

我在页面中有一个表单,它使用CodeIgniter框架将用户数据上传到我的在线服务器上。我可以使用HTTPS协议正常访问表单页面,但是当我尝试使用POST提交表单时,我收到了一个
403禁止:您没有访问此服务器的权限。
错误。可能是什么问题

.htaccess
文件:

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
视图中的“我的表单”属性。
$base\u url
变量是在
config.php
中配置的
base\u url()

<form name="new_article_form" id="new_article_form" method="POST" action="<?php echo $base_url; ?>entries/insert_article" enctype="application/x-www-form-urlencoded">
...
</form>

注意:从我可以得出的结论来看,错误在服务器端,因为使用该站点的移动应用程序的POST请求能够通过,但专门使用表单数据的浏览器POST请求无法通过。但是GET请求通过得很好。唯一可见的错误也出现在服务器错误日志上,说明找不到“404.html”页面。有人知道服务器端有什么可能会拒绝连接吗

更新:

HTTP标头:

Host: <***site***>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101     Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://<***site***>/entries/blogs
Cookie: PHPSESSID=ba4ce8f6cf3ebd19a443763fa8a187c0
Connection: keep-alive
主机:
用户代理:Mozilla/5.0(Windows NT 6.1;WOW64;rv:40.0)Gecko/20100101 Firefox/40.0
接受:text/html、application/xhtml+xml、application/xml;q=0.9,*/*;q=0.8
接受语言:en-US,en;q=0.5
接受编码:gzip,deflate
推荐人:https:///entries/blogs
Cookie:PHPSESSID=ba4ce8f6cf3ebd19a443763fa8a187c0
连接:保持活力
在表单操作中使用helper,然后检查控制器是否正在发布

<form name="new_article_form" id="new_article_form" method="POST" action="<?php echo site_url('entries/insert_article') ?>" enctype="application/x-www-form-urlencoded">

发现表单提交的数据被检测为服务器Mod Security防火墙上的XSS攻击,这就是为什么在加载CI之前请求被拒绝的原因。它现在已经在我的域名上被禁用,提交现在可以正常工作了。希望从现在起不再出现阻塞。

打开开发人员工具并检查“网络”选项卡。我想你的帖子很有用。@GuyT我这么做了,但它显示了403error@Peter您可以发布生成的HTML表单吗?我想问,MIME类型“multipart/form data”和“application/x-www-form-urlencoded”的可接受扩展是什么,正如我刚刚从标题输出和一些研究中了解到的,我的托管服务器不支持这些类型导航到host/index.php/entries/insert_article并在
insert_article
函数的第一行插入回显。您使用的是.htaccess吗?使用
site\u url()
没有帮助,仍然收到相同的错误我的浏览器没有错误跟踪,只有错误消息,我的服务器访问日志显示所有访问都被授予,我在CI日志中找不到错误堆栈跟踪either@Peter您是否检查了其他post请求是否正常工作?我刚刚尝试了对同一控制器的另一个post请求,但使用了不同的方法/功能和不同的视图:使用相同的技术,使用form helper,它正常工作。然后我切换了标签,再次尝试上面的页面,失败了。现在我不确定这里到底发生了什么。@Peter,你添加了自定义路由吗?我问你,为什么服务器将请求视为XSS攻击?你没有正确地编码数据吗?@GuyT也不确定,因为表单数据是通过POST请求提交的简单UTF-8编码文本,没有什么特别的。从我所看到的情况来看,有一些特殊字符正在被检查,这些字符触发了假阳性,例如我发布的数据中的分号和冒号
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['base_url'] = 'https://<***full_url***>/';
$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO';

$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'BG_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']   = 'c';
$config['function_trigger']     = 'm';
$config['directory_trigger']    = 'd'; // experimental not currently in use

$config['log_threshold'] = 2;
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '';
$config['encryption_key'] = '';
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;
$config['global_xss_filtering'] = FALSE;

$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = '************';
$config['csrf_cookie_name'] = '*************';
$config['csrf_expire'] = 3600;
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';

$config['rewrite_short_tags'] = FALSE;

$config['proxy_ips'] = '';

/* End of file config.php */
/* Location: ./application/config/config.php */
<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Entries extends CI_Controller 
{
public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->model("entries_model", "entries");
    }

    public function index($data = array())
    {

        ...//other code

        $form_attrs = array("name"=>"new_article_form", "id"=>"new_article_form", "enctype"=>"application/x-www-form-urlencoded");

        $form = form_open(base_url()."entries/insert_article", $form_attrs);

        //... form entries

        $form .= form_close();

        $data["form"] = $form;

        $this->load->view('entries_view', $data); //the form is displayed on the view properly, no errors present, exactly as shown above
    }

    public function insert_article()
    {
        $blogID = $this->input->post("blog");
        $title = mb_convert_encoding($this->input->post("title"), "UTF-8");

        //... other insert code

        $this->index($data);
    }

    public function blogs($result = "")
    {
        //... blogs view function
        $this->load->view('blogs_view', $data);
    }
}

    //... other code
?>
Host: <***site***>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101     Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://<***site***>/entries/blogs
Cookie: PHPSESSID=ba4ce8f6cf3ebd19a443763fa8a187c0
Connection: keep-alive
<form name="new_article_form" id="new_article_form" method="POST" action="<?php echo site_url('entries/insert_article') ?>" enctype="application/x-www-form-urlencoded">