POST提交后的CodeIgniter 302

时间:2019-04-05 02:00:39

标签: php codeigniter nginx http-status-code-302

我最近将我的codeigniter项目移至Nginx。它使用SSL,我可以访问网站的landing page

但是,这只是登录页面。我无法解决。每当我提交POST数据时,它都会重定向到自身。

我尝试print_r()上有POST数据,并且能够看到它,但仅此而已(我使用ion auth)。

这是我的登录控制器:

public function login()
{
    if($this->input->post()){
        echo "Yow"; //this works if you put die() nex to it.
    }
    if($this->ion_auth->logged_in() && !$this->ion_auth->is_admin())
    {
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        die();
        //echo "here"; die();
        //redirect('dashboard'); //disabled upon further notice
        redirect('directory');
    } else if($this->ion_auth->logged_in() && $this->ion_auth->is_admin()){
        redirect('admin');
    }else {
        $this->data['pagetitle'] = 'brunchwork | Login';
        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'Username', 'trim|required');
        $this->form_validation->set_rules('password', 'Password', 'trim|required');
        $msg = $this->session->flashdata('message');
        $this->data['message'] = $msg['message'];
        $this->data['alert_type'] = $msg['alert_type'];
        if ($this->form_validation->run() === FALSE)
        {
            $this->render('member/login');
        } else {
            if($this->input->post('remember_me')){
                $remember = 1;
            } else {
                $remember = 0;
            }
            //$remember = (bool) $this->input->post('remember_me');
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            if ($this->ion_auth->login($username, $password, $remember))
            {
                $sid = session_id();
                if($sid) {
                    //session_start();
                } else {
                    session_start();
                }
                //session_start();
                //redirect('dashboard'); //disabled upon further notice
                if($this->ion_auth->logged_in() && $this->ion_auth->is_admin())
    {
        //redirect('dashboard'); //disabled upon further notice
        redirect('admin');
    } else {
        redirect('directory');
    }
            }
            else
            {
                $_SESSION['message'] = $this->ion_auth->errors();
                $this->session->mark_as_flash(array('message' => $_SESSION['message'], 'alert_type' => 'error'));
                redirect('login');
            }
        }
    }
}

还有我的nginx conf:

server {
listen 80;
listen [::]:80;
server_name members.brunchwork.com www.members.brunchwork.com; 
return 307 https://members.brunchwork.com$request_uri;
# return 301 https://$server_name$request_uri;
# root   /home/dev/members.brunchwork.com/public_html;
# index index.html index.php;

}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name members.brunchwork.com www.members.brunchwork.com; 
root   /home/dev/members.brunchwork.com/public_html;
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /home/dev/members.brunchwork.com/godaddy-certs/bundle.crt;  
ssl_certificate_key /home/dev/members.brunchwork.com/godaddy-certs/members.brunchwork.com.key;


# Logging
error_log /home/dev/members.brunchwork.com/public_html/log/access_log;
access_log /home/dev/members.brunchwork.com/public_html/log/error_log;

location / {
#       Check if a file or directory index file exists, else route it to index.php.
#       try_files $uri $uri/ =404;
#       try_files $uri $uri/ /index.php?/$request_uri;
#       try_files $uri $uri/ /index.php;
    rewrite ^(.*)$ /index.php;
#       file doesn't exist, let CI handle it
    if (!-f $request_filename) {
            #rewrite ^(.*) /index.php?$1 last;
    rewrite ^(.*)$ /$1.php;
        }
  }

location ~ \.php {
#       try_files $uri $uri/ =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param SCRIPT_FILENAME /home/dev/members.brunchwork.com/public_html$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
#       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
     expires max;
     log_not_found off;
}

location ~ /\.ht {
    deny all;
}
}

可能是什么原因造成的?昨天还没有设置SSL时,我能够解决此问题,但是我找不到解决方案的出处,所以我在这里。

我们非常感谢您的帮助。

0 个答案:

没有答案