KKK
KKK

Reputation: 1662

How to check all post request from CodeIgniter

I want to check my application's all post request. I have created a new route option.

$route['(:any)'] = 'any';

this will call any controller. This is my any.php

if ( !defined('BASEPATH') ) exit('No direct script access allowed');

class Any extends CI_Controller {

    public function __construct() {
        parent::__construct();

    }


    function index(){
        if(  $_POST ){
            if( validate() ){
                // redirect to error controller
            }else{
                //redirect to current page url
            }
        }else{
            //redirect to current page url
        }
    }
}

But when i redirect via this function rediect($this->uri->uri_string), I got some error page. regarding cannot redirect to its self.

Is there any way to do this?

Upvotes: 0

Views: 973

Answers (1)

Code Prank
Code Prank

Reputation: 4250

You are doing it wrong it will stuck in a redirect loop... after first time it will always invoke the else condition where you have put the redirect... You can either load a view in else condition or redirect to other function where you load a view.

UPDATE

Here is your work aorund for what you are trying to achieve: Create a post_controller_construct hook with following code

class validate_post_request
{
    function validate_request()
    {
        //Here i am supposing your validate function is in helper 
        //which is included in autoload. The function returns
        //true if validation passed and false on failure
        if( !validate() ) {
            show_error('Your error message to display');
            exit;
        }
    }
}

Upvotes: 1

Related Questions