Jump to content

warning: trying to access array offset on value of type bool in sql.php


NaderH

Recommended Posts

Hello

I have this error

Quote

warning: trying to access array offset on value of type bool in sql.php on line 195

it appears between all pages while I am navigating from one page to another, this error appears and disappears immediately, but it appears and remains present when viewing sales reports page.

  /*--------------------------------------------------------------*/
  /* Function for checking which user level has access to the page
  /*--------------------------------------------------------------*/
   function page_require_level($require_level){
     global $session;
     $current_user = current_user();
     $login_level = find_by_groupLevel($current_user['user_level']);
     //if user not login
     if (!$session->isUserLoggedIn(true)):
            $session->msg('d','Please Sign in');
            redirect('index.php', false);
      //if Group status Deactive
     elseif($login_level['group_status'] === '0'):  //Line 195
           $session->msg('d','User Banned');
           redirect('home.php',false);
      //checking logged in User level and Require level is Less than or equal to
     elseif($current_user['user_level'] <= (int)$require_level):
              return true;
      else:
            $session->msg("d", "Error");
            redirect('home.php', false);
        endif;

     }

 

Edited by NaderH
Link to comment
Share on other sites

the error means that $login_level is a boolean (true or false) value, but the code expects it to be an array with a group_status element.

either something has changed to cause the find_by_groupLevel() function to return an unexpected value OR that part of the code (which is using an exact comparison with a string consisting of '0') never actually worked, wasn't fully tested, and was probably always producing this error, but the error wasn't being reported/displayed.

what is the code for the find_by_groupLevel() function and what is the expected value it should return for both a non-banned and a banned user?

Link to comment
Share on other sites

2 hours ago, mac_gyver said:

the error means that $login_level is a boolean (true or false) value, but the code expects it to be an array with a group_status element.

either something has changed to cause the find_by_groupLevel() function to return an unexpected value OR that part of the code (which is using an exact comparison with a string consisting of '0') never actually worked, wasn't fully tested, and was probably always producing this error, but the error wasn't being reported/displayed.

what is the code for the find_by_groupLevel() function and what is the expected value it should return for both a non-banned and a banned user?

It is to determine if the one who logging in is an admin or a seller or a user to display the home page that should appear to him according to his group(permission) level.

Link to comment
Share on other sites

20 minutes ago, mac_gyver said:

programming is an exact science. when someone points out a problem with some code and asks what is that code, it means you need to post exactly the code that was mentioned. if someone asks what is the expected value for something, it means to post exactly what that value is.

well, the expected value it should return is 0 or 1 to check if the user is allowed to log in or is banned, but for some reason it doesn't work, I mean if you banned the user he will be able to login.

consider that I am still a beginner.

Edited by NaderH
Link to comment
Share on other sites

30 minutes ago, mac_gyver said:

programming is an exact science. when someone points out a problem with some code and asks what is that code, it means you need to post exactly the code that was mentioned. if someone asks what is the expected value for something, it means to post exactly what that value is.

Well, I changed that lint to 

elseif($login_level['group_status'] != '1')

instead of 

elseif($login_level['group_status'] === '0')

and it caused that all users can login but can't view any page.

Edited by NaderH
Link to comment
Share on other sites

I think your tests are giving you incorrect results.  See the comments I've added to your code below.

function page_require_level($require_level)
{
	global $session;
	$current_user = current_user();
	$login_level = find_by_groupLevel($current_user['user_level']);
	//if user not login
	if (!$session->isUserLoggedIn(true))
	{
		$session->msg('d','Please Sign in');
		redirect('index.php', false);
	}
	//if Group status Deactive
	elseif($login_level['group_status'] === '0')	// is login_level a string??? 
	{
		$session->msg('d','User Banned');
		redirect('home.php',false);
	}
	elseif($current_user['user_level'] <= (int)$require_level)	// or is it an integer????
		return true;
	else
	{
		$session->msg("d", "Error");
		redirect('home.php', false);
	}
}

 

Edited by ginerjm
mistake in copying OP code
Link to comment
Share on other sites

I"m re-posting my version of your code again with some new comments.

function page_require_level($require_level)
{
	global $session;
	$current_user = current_user();
	$login_level = find_by_groupLevel($current_user['user_level']);
	//  SHOW THE RESULT OF ABOVE CALL
	//if user not login
	//  SHOW THE VALUE OF $SESSION BEFORE USING IT
		// EX: ECHO "session is </pre>",print_r($session,true),"</pre>";
	if (!$session->isUserLoggedIn(true))
	{
		$session->msg('d','Please Sign in');
		redirect('index.php', false);
	}
	//if Group status Deactive
	elseif($login_level['group_status'] === '0')	// is login_level a string???
	{
		$session->msg('d','User Banned');	
		redirect('home.php',false);
	}
	elseif($current_user['user_level'] <= (int)$require_level)	// or is it an integer????
		return true;
	else
	{
		$session->msg("d", "Error");
		redirect('home.php', false);
	}
}

is your use of redirect() the same as using the php header() command?  If so you should be doing an exit() right after running it.

Try doing my suggestions to debug your process and see what the vars you are using actually contain.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.