Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP Notice: Undefined variable: permission

Posted on 2011-05-02
9
Medium Priority
?
331 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:rgb192
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35505624
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.
0
 
LVL 9

Expert Comment

by:Vampireofdarkness
ID: 35505642
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.
0
 
LVL 1

Author Comment

by:rgb192
ID: 35506038
Why is there no function name
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

by:hielo
ID: 35506202
>>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
}
0
 
LVL 1

Author Comment

by:rgb192
ID: 35507566
so if there is no function name, the function can not be called
so i can just delete the function
correct??
0
 
LVL 9

Expert Comment

by:Vampireofdarkness
ID: 35507595
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.

0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 35507984
>>so if there is no function name, the function can not be called
Correct

>>so i can just delete the function
>>correct??
Strictly speaking, that is NOT correct. That is a code block, NOT a function. Since it is NOT a function you cannot say "i can just delete the function". Thus, you can delete that code block
0
 
LVL 1

Author Closing Comment

by:rgb192
ID: 35508073
most concise solution
0
 
LVL 9

Expert Comment

by:Vampireofdarkness
ID: 35508171
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question