我正在尝试创建登录系统。.我的登录系统可以100%完美地工作,但是问题是会话无法正确重定向。当我尝试索引中的函数时,它可以正常工作,但是如果我将函数移到父结构中,那就不好了。我认为父构造有任何问题,因为它也没有在父中加载库和模型。因此,我必须在每个函数中调用所有函数。检查我尝试的代码:
此代码可以正常工作:
<?php
/**
*
*/
class Adminpanel04736 extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('session');
}
public function index()
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->view('admin/dashboard');
}
public function list_of_post()
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->model('admin_blog_post');
$result['post_list']=$this->admin_blog_post->post_list();
$this->load->view('admin/post_list',$result);
}
// post delete id is comming from post_list php to delete the post
public function post_bin($post_delete_id)
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->trash_post($post_delete_id);
if ($result) {
redirect('adminpanel04736/list_of_post'); # code...
}
}
public function my_bin_post()
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->model('admin_blog_post');
$result['re']=$this->admin_blog_post->trash_bin_post();
$this->load->view('admin/trashed_post',$result);
}
// recycleing the post to repost
public function recycle_post($re)
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->repost($re);
if ($result) {
redirect('adminpanel/my_bin_post');
}
}
public function add_new_post()
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->view('admin/add_new_post');
}
// id is comming from delete post page to delete the post permenently
public function destroy_post($id)
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->destroy_post_permenently($id);
if ($result) {
redirect('adminpanel04736/my_bin_post');
}
}
public function post_content()
{
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->adding_the_posts($_POST);
if ($result) {
redirect('adminpanel04736/list_of_post');
}
}
public function admin_login()
{
$this->load->view('admin/lock1');
}
public function loginauthticate()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('admin_password','Password','required');
if ($this->form_validation->run()) {
$this->load->model('admin_blog_post');
$verification=$this->admin_blog_post->login_validation($_POST);
if ($verification) {
$username=$_POST['admin_user'];
$password=$_POST['admin_password'];
$session_data= array(
'admin_user' => $username
);
$this->session->set_userdata($session_data);
redirect(base_url().'adminpanel04736/');
}
else
{
$this->session->set_flashdata('error','Invalid Password');
redirect(base_url().'adminpanel04736/admin_login');
}
}
else
{
$this->admin_login();
}
}
}
?>
但这给我错误重定向太多次了。也不加载所有功能的库:
<?php
/**
*
*/
class Adminpanel04736 extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('session');
if ($this->session->userdata('admin_user')=='')
{
redirect(base_url().'adminpanel04736/admin_login');
}
}
public function index()
{
$this->load->view('admin/dashboard');
}
public function list_of_post()
{
$this->load->model('admin_blog_post');
$result['post_list']=$this->admin_blog_post->post_list();
$this->load->view('admin/post_list',$result);
}
// post delete id is comming from post_list php to delete the post
public function post_bin($post_delete_id)
{
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->trash_post($post_delete_id);
if ($result) {
redirect('adminpanel04736/list_of_post'); # code...
}
}
public function my_bin_post()
{
$this->load->model('admin_blog_post');
$result['re']=$this->admin_blog_post->trash_bin_post();
$this->load->view('admin/trashed_post',$result);
}
// recycleing the post to repost
public function recycle_post($re)
{
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->repost($re);
if ($result) {
redirect('adminpanel/my_bin_post');
}
}
public function add_new_post()
{
$this->load->view('admin/add_new_post');
}
// id is comming from delete post page to delete the post permenently
public function destroy_post($id)
{
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->destroy_post_permenently($id);
if ($result) {
redirect('adminpanel04736/my_bin_post');
}
}
public function post_content()
{
$this->load->model('admin_blog_post');
$result=$this->admin_blog_post->adding_the_posts($_POST);
if ($result) {
redirect('adminpanel04736/list_of_post');
}
}
public function admin_login()
{
$this->load->view('admin/lock1');
}
public function loginauthticate()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('admin_password','Password','required');
if ($this->form_validation->run()) {
$this->load->model('admin_blog_post');
$verification=$this->admin_blog_post->login_validation($_POST);
if ($verification) {
$username=$_POST['admin_user'];
$password=$_POST['admin_password'];
$session_data= array(
'admin_user' => $username
);
$this->session->set_userdata($session_data);
redirect(base_url().'adminpanel04736/');
}
else
{
$this->session->set_flashdata('error','Invalid Password');
redirect(base_url().'adminpanel04736/admin_login');
}
}
else
{
$this->admin_login();
}
}
}
?>
答案 0 :(得分:1)
您的admin_login是Adminpanel04736类的方法。 但是,当调用任何方法(包括admin_login)并且尚未登录用户时,您将再次重定向到admin_login。因此,您将获得无限重定向,而不是登录过程。
将admin_login移出类,或在重定向之前检查方法名称,类似
function __construct()
{
parent::__construct();
$this->load->library('session');
if ($this->session->userdata('admin_user')=='' and
$this->uri->segment(2) !== 'admin_login'))
{
redirect(base_url().'adminpanel04736/admin_login');
}
}
答案 1 :(得分:0)
在使用client id = your_client_id
server_token = your_server_token
**redirect_uri = com.uber.sdk.android.rides.samples.uberauth://redirect**
之前,您应该加载以下内容:redirect()
$this->load->helper('url');