0
votes

I Developed E-eCommerce Website in Codeigniter but I have one main problem.

In this site if I'm logged in the admin panel and don't log out from admin panel and then try to log into customer panel then it will automatically redirect to admin panel, even though I'm logged into customer panel.

You can test online: http://a2zshopping.my-board.org/?i=1 admin panel link is http://a2zshopping.my-board.org/admin.

Admin email: [email protected]
Password: admin
Customer: [email protected]
Pass: c%$#@!

Below is my code in controller/login class

//admin login
  public function __construct()
    {
        parent::__construct();
        if($this->session->userdata('admin_email'))
        {
            return redirect("admin");
        }


    }

    public function doLogin()
    {
        $post=$this->input->post();
        $this->load->model("Authentication","au");
        $data=$this->au->doLogin($post);
        if($data)
        {
            $this->session->set_userdata("admin_email",$data);
            return redirect("admin");
        }
        else
        {
            $this->session->set_flashdata("failed","Email and Password is not correct");
            return redirect("login");
        }

    }
    //customer login
    public function do_c_Login()
    {
        $post=$this->input->post();
        $this->load->model("Authentication","au");
        $data=$this->au->do_c_Login($post);
        if($data)
        {
            $c_email=$data->c_email;
            $c_id=$data->c_id;
            $this->session->set_userdata("c_email",$c_email);
            $this->session->set_userdata("c_id",$c_id);
            return redirect("shop/profile");
        }
        else
        {
            $this->session->set_flashdata([
                "msg"=>"Email and Password do match",
                "class"=>"danger",
                "heading"=>"ERROR"
                ]);
            return redirect("shop/login");
        }

    }

And this is code in controller/admin

public function __construct()
    {
        parent::__construct();
        if(!$this->session->userdata('admin_email'))
        {
            return redirect("login");
        }
        $this->load->model("Order_management","om");
        $this->load->model("user_management","um");
        $this->load->model("inventory_management","im");

    }

Below is code in shop/login for customer

if(!$this->session->userdata('c_email'))
        {
            return redirect("shop/login");
        }
1
Of course this will happen. You have a check to see if an admin email address is set in the persistent userdata ('admin_email'). Until this is cleared, they will always be redirected to admin area until you clear this userdata, but then they're not authorised as admin. You should not do forced redirects like this. You should separate the controller into two controllers: one for customer and one for admin which extend a base controller. - twistedpixel
Please explain more how to fix this, But email addresses that's store in Session Variable is different then why ? - Ahtasham

1 Answers

0
votes

of course it happen,because you set [email protected] in SESSION and when you leave admin panel,it is still in SESSION