Welcome Guest, Not a member yet? Register   Sign In
Order Page / 404 Issue
#1

(This post was last modified: 09-10-2016, 07:28 PM by flaboi.)

Ok so this issue just occured for me, if I visit mydomain.com/myorders I will see a default CI 404 error, but when someone logs in and visits that page they will see no errors and the page works. The way I would like it to work is when a user logs in they are redirected to that page and if a guest tries to access that page it will redirect them to mydomain.com/login. This is what is inside my UserController file:

Code:
/**
     * Loads the orders for a user.
     */
    public function myorders() {
        if(isset($_SESSION['user_login'])) {
            $user_id = $_SESSION['user_login'];
            $sale_orders = $this->Sale_acceptedoffer->get_for_user($user_id);
            $repair_orders = $this->Repair_acceptedoffer->get_for_user($user_id);
            $view = $this->load->view('user/myorders',[
                'sale_orders'=>$sale_orders,
                'repair_orders'=>$repair_orders,
                'devices'=>$this->Device->get(),
                'models'=>$this->Model->get(),
                'repops'=>$this->Repop->get(),
                'conditions'=>$this->Condition->get(),
            ],true);

            $this->load->view('layouts/master',[
                'title'=>'My Orders',
                'view'=>$view,
            ]);
        } else {
            show_404();
        }
    }
Code:
/**
     * Log a user in.
     */
    public function login_user() {
        $users = $this->User->get();
        $email = $this->input->post('email');
        $password = md5($this->input->post('password'));

        foreach ($users as $user_id => $user) {
            if(strtolower($user->email) == strtolower($email) && trim($user->password) == $password) {
                $_SESSION['user_login'] = $user->id;
                redirect('/myorders');
            } else {
                
            }

        }
        $_SESSION['login_error'] = true;
        redirect('login');
    }

The repair function is no longer working so should I just remove that line for repair?
Reply
#2

Replace
PHP Code:
show_404(); 

with
PHP Code:
redirect('login'); 
Reply
#3

Thanks, that worked perfectly!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB