view:
<?php
if($this->input->post('submit'))
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->db->select('username,password,admin_id');
$this->db->from('admin');
$where = "username='$username' and password = '$password'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->row_array();
$num = $query->num_rows();
if($num > 0)
{
$this->session->set_userdata('admin_id',$result);
redirect('admin/home');
}
else
{
echo "<p style='color: red;font-weight: 400;margin-right: 60px;'>Wrong email id or password! </p>";
}
}
?>
<form class="form-signin" method="post">
<input type="text" name="username" id="username" class="form-control" placeholder="username" required autofocus>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
<input type="submit" id="submit" name="submit" class="btn btn-lg btn-primary btn-block" value="Sign In">
</form>
controller: admin.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin extends CI_Controller {
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url', 'captcha', 'email'));
$this->load->model('ad_data');
}
public function home()
{
$data['admin_id'] = $this->session->userdata('admin_id');
print_r($data['admin_id']);
}
}
In this code I have create a simple login form and want to set my session variable value on my controller i.e. admin.php inside this controller I have print value of session but not get anything from it. I want to mention somthing and i.e. session value are enable on localhost but not working on godaddy hosting I do't know why? How can I fix this issue? Please help me.
Thank You