【发布时间】:2017-07-04 06:47:48
【问题描述】:
控制器:test.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url', 'captcha', 'email'));
$this->load->model('Fetch_data');
}
public function student()
{
$this->load->view('student-dashboard/index');
}
}
查看:login.php
<?php
if($this->input->post('login'))
{
$email2 = $this->input->post('email2');
$password2 = $this->input->post('password2');
$this->db->select('email,password');
$this->db->from('students');
$where = "email='$email2' and password = '$password2'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->result_array();
$num = $query->num_rows();
if($num >'0')
{
$this->db->select('email,password,student_id');
$this->db->from('students');
$where = "email='$email2' and password = '$password2'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->result_array();
$data['student_id'] = $this->session->set_userdata('student_id',$result);
if($result == true)
{
redirect('/test/student', $data);
}
}
else
{
echo "<p style='color: red;font-weight: bold;'>Wrong email id or password! </p>";
}
}
?>
<form method="post">
<div class="form-group">
<input type="text" name="email2" id="email2" placeholder="Enter Your Email" class="text-line"/>
</div>
<div class="form-group">
<input type="password" name="password2" id="password2" placeholder="Enter Your Password" class="text-line"/>
</div>
<div class="form-group">
<input type="submit" name="login" id="login" value="Login" class="btn btn-warning"/>
</div>
</form>
我是 codeigniter 的新手。在这段代码中,我正在创建登录表单,它运行良好。现在,我想将 student_id 存储到会话变量中,通过它我可以在我的所有页面上发出欢迎消息。那么,我该怎么做呢?请帮帮我。
谢谢
【问题讨论】:
-
但我也在使用 userdata 但是当我使用 print_r($data['student_id']);它什么也没显示
-
请任何人帮助我
-
试试我给你的链接
标签: php codeigniter