[eluser]downset[/eluser]
Hi,
I'm trying to implement the following login validation and session setting for a login form:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login2 extends CI_Controller {
public function index()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->library('form_validation');
$this->form_validation->set_rules("username", "Username", "required");
$this->form_validation->set_rules("password", "Password", "required");
if($this->form_validation->run() == false){
$headerData["title"] = "Login!";
$data["error_message"] = "please enter you user name and password <br>";
$this->load->view("view_header", $headerData);
$this->load->view("view_login_page", $data);
$this->load->view("view_footer");
}
else {
echo "you are logged in!";
//AK set error_reporting(0); to hide warning messages
//error_reporting(0);
$this->session->set_userdata('username', $username);
$this->session->set_userdata('password', $password);
redirect("../");
}
}
}
However I keep get the following error:
Quote:A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ci_basic_website/application/controllers/login2.php:25)
Filename: libraries/Session.php
Line Number: 672
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ci_basic_website/application/controllers/login2.php:25)
Filename: libraries/Session.php
Line Number: 672
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ci_basic_website/application/controllers/login2.php:25)
Filename: helpers/url_helper.php
Line Number: 546
I see in the CI documentation the following related to the URL helper (inc Redirect)
Quote:Note: In order for this function to work it must be used before anything is outputted to the browser since it utilizes server headers.
As I am loading a view on the first instance of loading /login2 if the input boxes for username and password don't contain values, is this causing the problem as the headers are being set on the initial load? If yes, can anyone please advise the best approach to submit the login form to itself, rather than submitting to a new page?
I am also running my test on MAMP, if that has any relevance. I have also checked that there is no white space or html before my main controller, as per instructions on some other topics, so this doesn't appear to be the cause of the errors.
I would appreciate any help the community can provide.
Thanks in advance!