Organizational Research By

Surprising Reserch Topic

way to tell if a post came from an ajax call in codeigniter


way to tell if a post came from an ajax call in codeigniter  using -'ajax,codeigniter,post'

I just started using CodeIgniter after using Zend for a while.  My new site has a feature where you register through Ajax.  In Zend I could use this to check if the incoming POST was through AJAX, and therefore from my site:

if(!$this->getRequest()->isXMLHttpRequest())


Is there a piece of code in CodeIgniter that does the same thing?  If I don't make sure it's an AJAX call, someone could theoretically register anything they wanted by creating a form to post to my controller.

Thanks!
    

asked Sep 15, 2015 by JeraldGaffne
0 votes
6 views



Related Hot Questions

2 Answers

0 votes
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {}

But since you are using codeigniter, its better to use their input class . See how to do it below.

 if($this->input->is_ajax_request()){
     //Execute Your Code
 }
answered Sep 15, 2015 by LuciaCuppred
0 votes

Since CodeIgniter 2.0, there is an easier way of checking for an ajax request.

Use: $this->input->is_ajax_request();

Doc: http://ellislab.com/codeigniter/user-guide/libraries/input.html

answered Sep 15, 2015 by KenGallegos

...