phpcodeigniterhttp-redirecthttp-status-code-302

CodeIgniter redirect() gives error: a 302 Found error was encountered while trying to use an ErrorDocument to handle the request


I am having a strange issue with my redirecting attempt in CodeIgniter. I'm trying to check the email in a registration form so that they can't enter the same email in the database and I'm getting a "found error" when I try to redirect to an error page.

Here is the code in my model:

public function checkEmail()
{
    $idCheck = $this->db->query('Select email from user_tbl Where email  ="'.$_POST["email"].'"');
        
    if ($idCheck->num_rows() > 0) { 
        redirect('home/errorPage');
    } else {
        redirect('home/');
    }   
}

The error message:

0 Found

The document has moved here.

Additionally, a 302 Found error was encountered while trying to use an ErrorDocument to handle the request.

HTTP/1.1 200 OK Date: Fri, 10 May 2013 01:18:37 GMT Content-Type: text/html Content-Length: 1653 Connection: keep-alive Server: Nginx / Varnish X-Powered-By: PHP/5.3.13


Solution

  • Codeigniter redirect function is written in the url helper class.

    check once, whether you have loaded the url helper class or not. OR check whether the redirect function is exists or not by

    var_dump(function_exists('redirect'));exit;
    

    and if it comes out to be false then add the below line, to load the url helper.

    $this->load->helper('url');
    

    and try once by passing the complete url for the redirect in the redirect function, or by adding a slash in front of "home" to "/home"

    About redirect functions:-

    The redirect function loads a local URI specified in the first parameter of the function call and built using the options specified in your config file.

    The second parameter allows the developer to use different HTTP commands to perform the redirect "location" or "refresh".