Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

PHP Notice: Undefined variable: permission

PHP Notice: Undefined variable: permission

can this variable ever be called

I dont know if I should delete this part of the code
//This function handles authorization of all requested pages
function intiateAC() {
	global $db;

	if(!isset($_SESSION['loggedin'])) {
		$url = OW_URL . 'login.php';
		header('Location: '.$url);
        //echo 'you are not logged in';
	}
}

 {
	//Permissions are seperated by a , and a space keep in mind if there are check permission errors!!!!!
	if(in_array($permission,$_SESSION['permissions'])) {
		return true;
	}
	else {
		return false;
	}
}

Open in new window

Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

The variable $permission is not being send or retreived by a global in that function.
I would delete that part of the code because it is useless without that parameter.
You're missing some of that code, it seems.

The notice you're getting is just saying that the variable $permission has not been set in the scope it is used. You need to either bring a global variable into the function, or define it within the function.
Avatar of rgb192

ASKER

Why is there no function name
Avatar of hielo
>>Why is there no function name
You are not defining it within a function. Your function definition  for intiateAC() ends on line 10.

On line 12 you deleted the function name. It PROBABLY was something like:

function hasPermission($permission) {
      //Permissions are seperated by a , and a space keep in mind if there are check permission errors!!!!!
      if(in_array($permission,$_SESSION['permissions'])) {
            return true;
      }
      else {
            return false;
      }
}

and then you would call it similar to:

define('MANAGE_USERS',1);
if( hasPermission(MANAGE_USERS) )
{
  //stuff here
}
Avatar of rgb192

ASKER

so if there is no function name, the function can not be called
so i can just delete the function
correct??
Correct. If you're using someone else's code, the chances are the function name that was there will be used elsewhere in the code and will throw up another error though.

If you downloaded it, check the original download to see if there was a function name and replace it.

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

most concise solution
Concise, but it didn't cover what happens if your function/code block really was meant to be a function (ie- errors elsewhere). Based on that the fact it has a return true/false, it certainly looks like a function as opposed to something that is supposed to be run inline. It also reiterated what had been said 55 minutes prior, but in a more pedantic way.