rgb192
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
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;
}
}
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.
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.
ASKER
Why is there no function name
>>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['p ermissions '])) {
return true;
}
else {
return false;
}
}
and then you would call it similar to:
define('MANAGE_USERS',1);
if( hasPermission(MANAGE_USERS ) )
{
//stuff here
}
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,$_
return true;
}
else {
return false;
}
}
and then you would call it similar to:
define('MANAGE_USERS',1);
if( hasPermission(MANAGE_USERS
{
//stuff here
}
ASKER
so if there is no function name, the function can not be called
so i can just delete the function
correct??
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.
If you downloaded it, check the original download to see if there was a function name and replace it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
I would delete that part of the code because it is useless without that parameter.