Failed to load resource the server responded with a status of 403 (forbidden) codeigniter

  1. Home
  2. Php
  3. Post Url 403 Forbidden In Codeigniter 3

Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter
Failed to load resource the server responded with a status of 403 (forbidden) codeigniter

POST url 403 forbidden in Codeigniter 3

Tags: php , codeigniter , http-status-code-403 Answers: | Viewed 6,551 times

Hi experts can you give me a suggestion, why I am getting this 403 forbidden on my code igniter currently running on my localhost.

403 forbidden



The process is like this:



  • I am using ajax for easy and smoothly access and retrieving of data from model, controller to the view the image below is my code in my views to controller.


    <div class="modal-header s-example-modal-sm" aria-labelledby="mySmallModalLabel">

    ×
    New Question Modal

    function question_save(){


    $.ajax({
    url : "<?php echo base_url('Mainx/insert_question_header');?>",
    crossDomain: true,
    contentType: "application/x-www-form-urlencoded",
    method: "POST",
    data: { name: 'question_header'},
    dataType: 'json',
    '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>',
    success: function(data){
    //alert('data save');
    },
    error: function (jqXHR, textStatus, errorThrown){
    alert('Error adding');
    }
    });
    }




And lastly from my controller and display the value that i type in my input under my view.


public function insert_question_header(){
$insert_header = array(
'question_header'=> $this->input->post("question_header")
);
//$this->db->insert('tb_question_header', $insert_header);
echo json_encode($insert_header);
redirect('Mainx/question_form/success' );
}


Some Code Answers


<div class="modal-header s-example-modal-sm" aria-labelledby="mySmallModalLabel">


$.ajax({
url : "<?php echo base_url('Mainx/insert_question_header');?>",
crossDomain: true,
contentType: "application/x-www-form-urlencoded",
method: "POST",
data: { name: 'question_header'},
dataType: 'json',
'<?php echo $this->security->get_csrf_token_name();
?>' : '<?php echo $this->security->get_csrf_hash();
?>',
success: function(data){ //alert('data save');
},
error: function (jqXHR, textStatus, errorThrown){ alert('Error adding');
}
});
}


public function insert_question_header(){
$insert_header = array(
'question_header'=>
$this->input->post("question_header")
);
//$this->db->insert('tb_question_header', $insert_header);
echo json_encode($insert_header);
redirect('Mainx/question_form/success' );
}


<script type="text/javascript">
function q_header() { var question = document.getElementById('question').value;
$.ajax({
url: "<?php echo base_url('Mainx/insert_question_header');?>",
type: "post",
data: {'<?php echo $this->security->get_csrf_token_name();
?>':'<?php echo $this->security->get_csrf_hash();
?>',"question":question},
success: function(){
alert("success");
},
error:function(){
alert("failure");
} });
} </script>


$config['csrf_regenerate'] = FALSE;


$.ajax({
url : "<?php echo base_url('Mainx/insert_question_header');?>",
crossDomain: true,
contentType: "application/x-www-form-urlencoded",
method: "POST",
data: { name: 'question_header', '<?php echo $this->security->get_csrf_token_name();
?>' : '<?php echo $this->security->get_csrf_hash();
?>' },
dataType: 'json',
success: function(data){ //alert('data save');
},
error: function (jqXHR, textStatus, errorThrown){ alert('Error adding');
}
});


More Answers Related Post Url 403 Forbidden In Codeigniter 3

php - CodeIgniter 3 - 403 Forbidden on POST from …

1 week ago Apr 12, 2021  · POST url 403 forbidden in Codeigniter 3. Ajax request with codeigniter 403 (forbidden) 403 Forbidden Access to CodeIgniter controller from ajax request. etc... php jquery ajax codeigniter. Share. Follow edited Apr 12, 2021 at …

Show details

See also: Php Jquery Ajax Codeigniter

CodeIgniter 3 - 403 Forbidden on POST from jQuery.ajax() …

1 week ago Apr 20, 2021  · CodeIgniter Forums Using CodeIgniter General Help CodeIgniter 3 - 403 Forbidden on POST from jQuery.ajax() asynchronous …

Show details

See also: Ajax

POST via Ajax returns 403 with CSRF enabled

1 week ago Apr 08, 2020  · I've deployed the latest Codeigniter 4.0.2 version and I have an issue when submitting a form with Post method via Ajax when CSRF is enabled, I've tried my best to figure out what is wrong but still no luck. Notice that: - When CSRF is disabled, the Ajax call is successful. - If I don't use Ajax and I enable CSRF, the controller handles ...

Show details

codeigniter - 403 error with codeignitor - Server Fault

1 week ago 3 Answers. Thanks for the tip. I ultimately dealt with the issue by setting up a redirect in CPanel. CodeIgniter uses the Front-Conroller pattern, which means all requests are marshalled through a single controller, in this case index.php. If you don't want that to show up in the URL, you need to setup up rewrites on your server.

Show details

See also: Php Codeigniter

Please leave your answer here: