[eluser]manojchakri[/eluser]
Hi all.
Now I wrote a login validation form with database checking.Now after successfully logging in for the user I want to create session variable and get the user data from the session information. But When I am creating session it is giving error like "Cannot modify Header Information".My code is like this.
Controller:
Code:
class Form extends Controller
{
function Form()
{
parent::Controller();
$this->load->library('session');
}
function index()
{
//$this->load->view('header');
echo $this->session->userdata('user_name');
$this->load->view('simple');
$this->load->view('signup');
}
function post_form()
{
$username = $this->input->post('username');
echo $username;
$pwd=$this->input->post('pwd');
$this->load->model('simpl');
if($this->simpl->test1($username,$pwd)===TRUE)
{
$user=array('user_name'=>$username,'logged_in'=>TRUE);
$this->session->set_userdata($user);
echo $this->session->userdata('user_name');
echo '<BR>successfully logged in<a >Back to Home Page</a>';
}
}
Here my model test1 function is validating for user data from database and returning true.
But when session is setting user data then the error like this is coming
Quote:A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\CodeIgniter_1.7.1\system\application\controllers\form.php:72)
Filename: libraries/Session.php
Line Number: 662
What should I do? I need to display the logged in user name like "welcome <user>" on every page and a logout link which should close the session and display "welcome guest" on every page and login link.Please help me with some sample code..Thanks in advance.