后,我用一个简单的功能笨登录成功后重定向我的网页。笨:PHP不工作第一次刷新
当页面加载我的内容被加载,而不是PHP代码标记之间。
这不是rewrite_short_tags
这是我猜的问题,因为当我按F5所有装载好。
为什么我需要刷新我的页面F5才能看到结果?
控制器:
session_start();
class Login_form extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
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');
echo validation_errors();
include "application/views/forms/login.php";
}
else
{
//Refresh index
redirect('index', '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;
}
}
function logout() {
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('index', 'refresh');
}
}
的观点:
<h1>My cms</h1>
<?php
if (!$this->session->userdata('logged_in')) {
echo form_open('login_form', array('id' => 'loginForm')); ?>
<div id="formLoginDiv">
<?php include "forms/login.php"; ?>
</div>
</form>
<?php } else { ?>
<a href="<?php echo site_url('login_form/logout')?>">Logout</a>
<?php } ?>
我跑的观点一样,:redirect('index', 'refresh');
现在,它加载所有的好时候,如果第一次启动了这一观点。在ajax完成检查并返回true后,我刷新此视图。但注销链接不被查看。
更新:
我试过no-cache
头把他们安置在不同的地方(甚至在主要的index.php)。
其次,我不使用$template
var,所以我得到一个错误。
我已经加入了相关的代码和更新在2“答案”由OP给出的问题和投票重新开放。 – GitaarLAB 2014-09-07 04:34:01