观点:
<?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']);
}
}
在这段代码中我创建了一个简单的登录表单,并希望在我的控制器上设置会话变量值,即在该控制器内部的admin.php我有会话的打印值,但没有从中获取任何内容。我想提一下somthing,即会话值是在localhost上启用但不在godaddy主机上工作我不知道为什么?我该如何解决这个问题?请帮帮我。
谢谢