• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Adding OR / || to if statement

#1
I want to be able to do two checks on my MY_Controller.php

Can check if my session token is set like

PHP Code:
if (!in_array($route$ignore) && !$this->session->userdata('token')) { 


That works fine but want to add another another check for user_id it throws The page isn’t redirecting properly error


PHP Code:
if (!in_array($route$ignore) && !$this->session->userdata('token') || !$this->session->userdata('user_id')) { 


How can I have both session userdata in there?


PHP Code:
<?php

class MY_Controller extends CI_Controller {

    public function __construct() {
        parent::__construct();

        $this->lang->load('general''english');

        $route $this->router->directory $this->router->class;

        $ignore = array(
            'account/login',
            'account/logout'
        );

        if (!in_array($route$ignore) && !$this->session->userdata('token') || !$this->session->userdata('user_id')) {
            
            $this
->auth->logout();
            
            $this
->session->set_flashdata('error'$this->lang->line('session_expire'));

            redirect(base_url("account/login"));

        }

    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
Hi,
I did not understand what you meant by "but throws redirect error",
can you try in following way: 
if (!in_array($route$ignore) && (!$this->session->userdata('token') || !$this->session->userdata('user_id')))
Reply

#3
(02-23-2017, 10:13 PM)neuron Wrote: Hi,
I did not understand what you meant by "but throws redirect error",
can you try in following way: 
if (!in_array($route$ignore) && (!$this->session->userdata('token') || !$this->session->userdata('user_id')))

Meaning The page isn’t redirecting properly fire fox error only when I added the || or part
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#4
(02-23-2017, 10:13 PM)neuron Wrote: Hi,
I did not understand what you meant by "but throws redirect error",
can you try in following way: 
if (!in_array($route$ignore) && (!$this->session->userdata('token') || !$this->session->userdata('user_id')))

All working now thanks
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.