Sunday, 8 October 2017

codeigniter login Cannot modify header information

itemprop="text">


I test on my localhost is
working well and now show any error but after upload to the godaddy server. it is
codeigniter version 2.2.6.



this error show in
the login page.



Error Message
1



Message: Cannot modify header
information - headers already sent by (output started at
/home/user/public_html/ngapali/test/application/controllers/admin/user.php:1)



Filename:
libraries/Session.php




Line Number:
433



Error Message 2



Message: Cannot modify header information -
headers already sent by (output started at
/home/user/public_html/ngapali/test/application/controllers/admin/user.php:1)



Filename:
libraries/Session.php



Line Number:
689




Admin Controller of My Controller




class
Admin_Controller extends MY_Controller{

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



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

$this->load->library('form_validation');

$this->load->library('session');


$this->load->model('user_m');
$this->load->model('roomtype_m');

$this->load->model('room_m');

$this->load->model('roomcapacity_m');




//login check
$exception_uris = array(

'admin/user/login',
'admin/user/logout'
);


if(in_array(uri_string(), $exception_uris) == FALSE) {

if($this->user_m->loggedin() == FALSE) {

redirect('admin/user/login');
}


}
}}?>


My
login page /user/login



Controller





class
User extends Admin_Controller {

function __construct(){

parent::__construct();

}

public function
index() {
$this->data['users'] = $this->user_m->get();

$this->data['subview'] = 'admin/user/index';


$this->load->view('admin/_layout_main',$this->data);
}


public
function login() {
$dashboard = 'l0gadmin/dashboard';

$this->user_m->loggedin() == FALSE || redirect($dashboard);


$rules = $this->user_m->rules;

$this->form_validation->set_rules($rules);


if($this->form_validation->run() == TRUE){

if($this->user_m->login() == TRUE){
redirect($dashboard);

}else{
$this->session->set_flashdata('error','That email/password
combination does not exist ');

redirect('admin/user/login','refresh');
}
}

$this->data['subview'] = 'admin/user/login';

$this->load->view('admin/_layout_modal',$this->data);

}

public
function logout(){
$this->user_m->logout();

redirect('admin/user/login');
}}?>


Model





class
User_m extends MY_Model {



function
__construct(){

parent::__construct();
}



public
function login(){
$user = $this->get_by(array(
'email'=>
$this->input->post('email'),
'password' =>
$this->hash($this->input->post('password')),

),TRUE);

if(count($user)){
$data = array(

'name'=> $user->name,

'email' =>
$user->email,
'id'=> $user->id,

'loggedin'=>TRUE,
);

$this->session->set_userdata($data);

}
}

public function logout(){

$this->session->sess_destroy();

}
public function
loggedin(){
return (bool)
$this->session->userdata('loggedin');
}


public
function hash($string){
return hash('sha512', $string .
config_item('encryption_key'));
}}?>



View
Page of login



             class="row">

Admin
Login




echo
validation_errors();

echo form_open('');
$email =
array(

'name' => 'email',
'class' =>
'form-control',
'placeholder' => 'Email Address'


);
echo form_input($email) . "
";



$password = array(
'name' => 'password',
'class' =>
'form-control',
'placeholder' => 'Password'
);
echo
form_password($password) . "
";

$submit =
array(
'name' => 'submit',
'class' => 'form-control btn
btn-primary',

'value' => 'Login'
);
echo
form_submit($submit);

echo form_close();


?>








i
search this problem can be of open and closed tag. I try to add all the page but it
still show error. Why?.


itemprop="text">
class="normal">Answer



Read the
error message:





output started at

/home/user/public_html/ngapali/test/application/controllers/admin/user.php:1





/user.php
file has some blank character on line 1



check
for any blank space before
tag.



Remove it and refresh error will be go
away.



One more suggestion,
Omit ending
php tags ?> in controller and model
files.




Read more here : href="https://stackoverflow.com/questions/3219383/why-do-some-scripts-omit-the-closing-php-tag">Why
would one omit the close tag?


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...