Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
403 prohibido incluso pongo el nombre csrf y el valor en forma

Estoy activando la seguridad CSRF en mi código:

 $config['csrf_protection'] = TRUE; $config['csrf_token_name'] = 'csrf_test_name'; $config['csrf_cookie_name'] = 'csrf_cookie_name'; $config['csrf_expire'] = 7200; $config['csrf_regenerate'] = TRUE; $config['csrf_exclude_uris'] = array();

Ahora, estoy agregando un campo oculto en mi formulario:

 <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">

En mi publicación de formulario, obtengo los datos:

 csrf_test_name:50711c69fc79244945f0aaecf7ac1aa4 teacher_name: teacher_mobile: teacher_email: teacher_about:

Pero, todavía recibo errores como:

 <h1>An Error Was Encountered</h1> <p>The action you have requested is not allowed.</p> </div>

Estoy enviando datos usando una llamada ajax:

 submitHandler: function (form) { var URL = $("#teacherForm").attr("action"); var METHOD = $("#teacherForm").attr("method"); $.ajax({ type: METHOD, url: URL, data: $(form).serialize(), success: function (data) { var data = $.parseJSON(data); ...... ......

¿Qué estoy haciendo mal?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Le sugiero que cambie una configuración de configuración CSRF:

 $config['csrf_regenerate'] = FALSE;

y ver si eso ayuda.

Si desea regenerar el hash en cada POST y usar AJAX, deberá devolver el nuevo hash al navegador y actualizar los valores del campo oculto CSRF para que el próximo POST pase la verificación de seguridad.

Sería prudente utilizar Form Helper en lugar de crear manualmente la entrada CSRF oculta. En una vista que se vería como

 echo form_open('controller/method');

Documentación sobre form_open() aquí .

Lea acerca de cómo usar form_open() para agregar el CSRF oculto aquí .

over 4 years ago · Santiago Trujillo Report

0

Una vez intente agregar csrf en la solicitud ajax que no está en el formulario. Funcionó para mí

Aquí está el código:

 submitHandler: function (form) { var URL = $("#teacherForm").attr("action"); var METHOD = $("#teacherForm").attr("method"); var data= $(form).serialize(); var post_data = { 'result': data, '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>' }; $.ajax({ type: METHOD, url: URL, data:post_data, success: function (data) { var data = $.parseJSON(data); ...... ......
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!