简体   繁体   English

为什么 CodeIgniter 中的重定向功能在实时服务器上不起作用,但在 localhost 上运行良好

[英]Why in CodeIgniter redirect function is not working on live server, but working fine on localhost

After Installation.安装后。 I set the login as default controller and want to go to dashboard of admin but after submitting login details instead of redirecting to the dashboard, it is redirecting to install controller again.我将登录设置为默认控制器并想转到管理员的仪表板,但在提交登录详细信息而不是重定向到仪表板后,它正在重定向以再次安装控制器。

can anyone help me?谁能帮我?

My login controller is login.php:我的登录控制器是 login.php:

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Login extends CI_Controller
{


    function __construct()
    {
        parent::__construct();
        $this->load->database();

    }

    /***default functin, redirects to login page if no admin logged in yet***/
    public function index()
    {
        if ($this->session->userdata('admin_login') == 1)
            redirect(base_url() . 'index.php?admin/dashboard', 'refresh');

        if ($this->session->userdata('doctor_login') == 1)
            redirect(base_url() . 'index.php?doctor/dashboard', 'refresh');

        if ($this->session->userdata('patient_login') == 1)
            redirect(base_url() . 'index.php?patient/dashboard', 'refresh');

        if ($this->session->userdata('nurse_login') == 1)
            redirect(base_url() . 'index.php?nurse/dashboard', 'refresh');

        if ($this->session->userdata('pharmacist_login') == 1)
            redirect(base_url() . 'index.php?pharmacist/dashboard', 'refresh');

        if ($this->session->userdata('laboratorist_login') == 1)
            redirect(base_url() . 'index.php?laboratorist/dashboard', 'refresh');

        if ($this->session->userdata('accountant_login') == 1)
            redirect(base_url() . 'index.php?accountant/dashboard', 'refresh');



        $config = array(
            array(
                'field' => 'login_type',
                'label' => 'Account Type',
                'rules' => 'required|xss_clean'
            ),
            array(
                'field' => 'email',
                'label' => 'Email',
                'rules' => 'required|xss_clean|valid_email'
            ),
            array(
                'field' => 'password',
                'label' => 'Password',
                'rules' => 'required|xss_clean|callback__validate_login'
            )
        );

        $this->form_validation->set_rules($config);
        $this->form_validation->set_message('_validate_login', ucfirst($this->input->post('login_type')) . ' Login failed!');
        $this->form_validation->set_error_delimiters('<div class="alert alert-error">
                                <button type="button" class="close" data-dismiss="alert">×</button>', '</div>');

        if ($this->form_validation->run() == FALSE) {
            $this->load->view('login');
        } else {
            if ($this->session->userdata('admin_login') == 1)
                redirect(base_url() . 'index.php?admin/dashboard', 'refresh');

            if ($this->session->userdata('doctor_login') == 1)
                redirect(base_url() . 'index.php?doctor/dashboard', 'refresh');

            if ($this->session->userdata('patient_login') == 1)
                redirect(base_url() . 'index.php?patient/dashboard', 'refresh');

            if ($this->session->userdata('nurse_login') == 1)
                redirect(base_url() . 'index.php?nurse/dashboard', 'refresh');

            if ($this->session->userdata('pharmacist_login') == 1)
                redirect(base_url() . 'index.php?pharmacist/dashboard', 'refresh');

            if ($this->session->userdata('laboratorist_login') == 1)
                redirect(base_url() . 'index.php?laboratorist/dashboard', 'refresh');

            if ($this->session->userdata('accountant_login') == 1)
                redirect(base_url() . 'index.php?accountant/dashboard', 'refresh');
        }

    }

    /***validate login****/
    function _validate_login($str)
    {
        if ($this->input->post('login_type') == '') {
            $this->session->set_flashdata('flash_message', get_phrase('login_failed'));
            return FALSE;
        }
        $query = $this->db->get_where($this->input->post('login_type'), array(
            'email' => $this->input->post('email'),
            'password' => $this->input->post('password')
        ));
        if ($query->num_rows() > 0) {
            $row = $query->row();
            if ($this->input->post('login_type') == 'admin') {
                $this->session->set_userdata('login_type', 'admin');
                $this->session->set_userdata('admin_login', '1');
                $this->session->set_userdata('admin_id', $row->admin_id);
            }
            if ($this->input->post('login_type') == 'doctor') {
                $this->session->set_userdata('login_type', 'doctor');
                $this->session->set_userdata('doctor_login', '1');
                $this->session->set_userdata('doctor_id', $row->doctor_id);
            }
            if ($this->input->post('login_type') == 'patient') {
                $this->session->set_userdata('login_type', 'patient');
                $this->session->set_userdata('patient_login', '1');
                $this->session->set_userdata('patient_id', $row->patient_id);
            }
            if ($this->input->post('login_type') == 'nurse') {
                $this->session->set_userdata('login_type', 'nurse');
                $this->session->set_userdata('nurse_login', '1');
                $this->session->set_userdata('nurse_id', $row->nurse_id);
            }
            if ($this->input->post('login_type') == 'pharmacist') {
                $this->session->set_userdata('login_type', 'pharmacist');
                $this->session->set_userdata('pharmacist_login', '1');
                $this->session->set_userdata('pharmacist_id', $row->pharmacist_id);
            }
            if ($this->input->post('login_type') == 'laboratorist') {
                $this->session->set_userdata('login_type', 'laboratorist');
                $this->session->set_userdata('laboratorist_login', '1');
                $this->session->set_userdata('laboratorist_id', $row->laboratorist_id);
            }
            if ($this->input->post('login_type') == 'accountant') {
                $this->session->set_userdata('login_type', 'accountant');
                $this->session->set_userdata('accountant_login', '1');
                $this->session->set_userdata('accountant_id', $row->accountant_id);
            }
            return TRUE;
        } else {
            $this->session->set_flashdata('flash_message', get_phrase('login_failed'));
            return FALSE;
        }
    }
    /*******LOGOUT FUNCTION *******/
    function logout()
    {
        $this->session->unset_userdata();
        $this->session->sess_destroy();
        $this->session->set_flashdata('flash_message', get_phrase('logged_out'));
        redirect(base_url() . 'index.php?login', 'refresh');
    }

    /***DEFAULT NOR FOUND PAGE*****/
    function four_zero_four()
    {
        $this->load->view('four_zero_four');
    }

    /***RESET AND SEND PASSWORD TO REQUESTED EMAIL****/
    function reset_password()
    {
        $account_type = $this->input->post('account_type');
        if ($account_type == "") {
            redirect(base_url(), 'refresh');
        }
        $email  = $this->input->post('email');
        $result = $this->email_model->password_reset_email($account_type, $email); //SEND EMAIL ACCOUNT OPENING EMAIL
        if ($result == true) {
            $this->session->set_flashdata('flash_message', get_phrase('password_sent'));
        } else if ($result == false) {
            $this->session->set_flashdata('flash_message', get_phrase('account_not_found'));
        }


    }

    /***LOGIN AS ANOTHER USER LIKE DOCTOR,PATIENT,PHARMACIST,LABORATORIST ETC******/
    function login_as($user_type = '', $user_id = '')
    {
        $this->session->set_userdata('login_type', $user_type);
        $this->session->set_userdata($user_type . '_login', '1');
        $this->session->set_userdata($user_type . '_id', $user_id);
        redirect(base_url() . 'index.php?' . $user_type . '/dashboard', 'refresh');
    }
}

Did you check the cookie in the live server?您是否检查了实时服务器中的 cookie? I had experienced something similar like yours.我也经历过和你类似的事情。 The redirect() function was not work in live server, but in fact the thing which doesn't work well was the user_data session has gone everytime page loaded. redirect()函数在实时服务器中不起作用,但实际上不起作用的是每次加载页面时user_data会话都消失了。 I just allowed the cookie $config['sess_cookie_name'] = "MY-COOKIE*******" in live server and everything goes well.我只是在实时服务器中允许 cookie $config['sess_cookie_name'] = "MY-COOKIE*******"并且一切顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Codeigniter重定向不适用于实时服务器,但适用于本地主机 - Codeigniter redirect is not working on live server but working in localhost 重定向功能在实时服务器上不起作用。 但是在本地主机上工作 - Redirect function is not working on the live server. But working on localhost javascript在localhost上工作正常,但在实时服务器上却不能 - javascript working fine in localhost but not on live server CodeIgniter邮件无法在服务器上运行,但可以在本地主机上正常工作 - CodeIgniter mail not working on server but works fine localhost 会话不在localhost中工作但在实时服务器中工作(Codeigniter) - Sessions not working in localhost but work in live server (Codeigniter) 为什么 CodeIgniter 中的重定向功能不起作用? - Why redirect function in CodeIgniter not working? PHP站点可以在本地主机上正常运行,但不能在实时服务器上运行 - PHP site running fine on localhost but not working on a live server php 代码在 xampp 本地主机上运行良好,但在实时服务器上运行不正常 - php code works fine on xampp localhost but not working on live server CodeIgniter 显示在服务器上找不到 404,但在 localhost (xampp) 中工作正常 - CodeIgniter shows 404 not found on the server but working fine in localhost (xampp) 重定向在实时服务器上不起作用 - the redirect is not working on live server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM