PHP CodeIgniter: успешный вход в систему ion-auth обновляет, выходит и перенаправляет на вход - PullRequest
0 голосов
/ 30 августа 2018

Я недавно унаследовал работающий код веб-сайтов, разработанный с PHP в CodeIgnitor, и я пытаюсь развивать его дальше. При попытке запустить локально (xampp) я столкнулся с проблемой:

Код прекрасно работает и выводит меня на страницу входа. Там я вхожу, используя ion-auth, который успешно продолжается, сохраняет сеанс (это работает) и переходит на целевую страницу. Тем не менее, как только любая страница загружается после входа в систему, она мгновенно выходит из системы и возвращается на страницу входа в систему.

Единственное, что изменилось в коде по сравнению с живым веб-сайтом, - это база данных, к которой он подключается, базовый URL и некоторая навигация. В чем может быть проблема здесь? Это может быть проблема с xampp, ion-auth или какой-либо конфигурацией?

// log the user in
public function login()
{
    $this->data['title'] = $this->lang->line('login_heading');

    // validate form input
    $this->form_validation->set_rules('identity', str_replace(':', '', $this->lang->line('login_identity_label')), 'required');
    $this->form_validation->set_rules('password', str_replace(':', '', $this->lang->line('login_password_label')), 'required');

    if ($this->form_validation->run() == true)
    {
        // check to see if the user is logging in
        // check for "remember me"
        $remember = (bool) $this->input->post('remember');

        if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember))
        {
            // if the login is successful
            // redirect them back to the home page
            $this->session->set_flashdata('message', $this->ion_auth->messages());
            redirect('/', 'refresh');
        }
        else
        {
            // if the login was un-successful
            // redirect them back to the login page
            $this->session->set_flashdata('message', $this->ion_auth->errors());
            redirect('auth/login', 'refresh'); // use redirects instead of loading views for compatibility with MY_Controller libraries
        }
    }
    else
    {
        // the user is not logging in so display the login page
        // set the flash data error message if there is one
        $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

        $this->data['identity'] = array('name' => 'identity',
            'id'    => 'identity',
            'type'  => 'text',
            'value' => $this->form_validation->set_value('identity'),
        );
        $this->data['password'] = array('name' => 'password',
            'id'   => 'password',
            'type' => 'password',
        );

        $this->_render_page('auth/login', $this->data);
    }
}

Как предположил Мартин, я попробовал session_start();, который показал следующее:

A PHP Error was encountered
Severity: Warning

Message: ini_set(): A session is active.
You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 281

Backtrace:

File: C:\Programs\xampp\htdocs\modules\applications\azdemo\controllers\Shared.php
Line: 8
Function: __construct

File: C:\Programs\xampp\htdocs\modules\customers\azdemo\index.php
Line: 315
Function: require_once

1 Ответ

0 голосов
/ 05 сентября 2018

Временное решение этой проблемы путем понижения с php7.2.6 до php5.5.38. Возможно, некоторые библиотеки нуждаются в обновлении. Я также переключился с xampp на mamp pro 4 из-за проблем с локальным доменом и того факта, что вы не можете так просто понизить версию php xampp.

Надеюсь, это поможет кому-то в будущем.

...