Welcome Guest, Not a member yet? Register   Sign In
Is there a way of detecting POST data in URL requests before routing them?
#11

[eluser]Cristian Gilè[/eluser]
[quote author="cahva" date="1296108845"]BTW, $_POST is a superglogal and is always defined so using isset($_POST) wont work. Better to check if its an ajax request. If you use CI2, you can use what kirkaracha told you or simply put this:
Code:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
..to application/config/constants.php

With that constant its easy to know if its an ajax request or not.[/quote]

Input class is not loaded when routes are processed so $this->input->is_ajax_request() doesn't work. isset($_POST) or define a constant are the best solution.


Cristian Gilè
#12

[eluser]sorenchr[/eluser]
Using a combination of isset($_POST) and the IS_AJAX constants I got it to work. Thanks to you all!
#13

[eluser]cahva[/eluser]
The $_POST is still always set because its a superglogal, so isset($_POST) is not needed at all. If you want to check if theres anything posted even this is better:
Code:
if (IS_AJAX && $_POST)
{
  // Do something. Its an ajax call and $_POST contains something
}




Theme © iAndrew 2016 - Forum software by © MyBB