【发布时间】:2018-09-25 20:12:49
【问题描述】:
查看:
<?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>
控制器: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,我有会话的打印值,但没有从中得到任何东西。我想提一些东西,即会话值在 localhost 上启用,但不能在 Godaddy 托管上工作,我不知道为什么?我该如何解决这个问题?请帮帮我。
谢谢
【问题讨论】:
-
你加载了会话库吗?
-
是的,我已经在自动加载里面加载了
-
你设置会话路径了吗?
-
在 home() 函数中创建会话?
-
是的,在 home() 函数中我创建了会话
标签: php codeigniter