Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class VerifyLogin extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- $this->load->model('user','',TRUE);
- $this->load->helper('url');
- }
- function index()
- {
- //This method will have the credentials validation
- $this->load->library('form_validation');
- $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
- $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
- if($this->form_validation->run() == FALSE)
- {
- //Field validation failed. User redirected to login page
- $this->load->view('login_view');
- }
- else
- {
- //Go to private area
- redirect('home', 'refresh');
- }
- }
- function check_database($password)
- {
- //Field validation succeeded. Validate against database
- $username = $this->input->post('username');
- //query the database
- $result = $this->user->login($username, $password);
- if($result)
- {
- $sess_array = array();
- foreach($result as $row)
- {
- $sess_array = array(
- 'id' => $row->id,
- 'username' => $row->username
- );
- $this->session->set_userdata('logged_in', $sess_array);
- }
- return TRUE;
- }
- else
- {
- $this->form_validation->set_message('check_database', 'Invalid username or password');
- return false;
- }
- }
- }
- <html>
- <head>
- <title>OpediaLab</title>
- </head>
- <body>
- <h1></h1>
- <?php echo validation_errors(); ?>
- <?php echo form_open('verifylogin'); ?>
- <link rel="stylesheet" type="text/css" href="<?=base_url()?>style.css"/>
- <label for="username">Username:</label>
- <input type="text" size="20" id="username" name="username"/>
- <br/>
- <label for="password">Password:</label>
- <input type="password" size="20" id="passowrd" name="password"/>
- <br/>
- <input type="submit" value="Login"/>
- </form>
- </body>
- </html>
- body{
- background-image: url("C:/wamp/www/CI/application/views/immagini/Opedia_LAB.png");
- background-color: green;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement