[eluser]toopay[/eluser]
Code:
if($this->session->userdata('loggedin')==NULL) redirect('login');
Thats why you receive 302 in header response.
In addition, you could do the database stuff on your model, using CI DB class, rather than manual connection like that. Also, consider what i suggest before, to using an API!