[SOLVED] Undefined Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

[SOLVED] Undefined Function

Post by xjake88x »

Hello, I'm making a content managment system such as PHP nuke, and it's coming along good except I've run into a problem:

Fatal error: Call to undefined function: check_level() in ...\jakesys\postnews.php on line 10

Here is the structure of pages:
index.php includes header.php
...header.php declares function check_level
index.php includes postnews.php
...postnews.php calls function check_level

Here is the function declared right under the session_start of header.php:

Code: Select all

function check_level($req_lvl){
	if($_SESSION['level']>=$req_lvl){
		return true;
	}else{
		echo "You lack permission to use access this page.<br />";
		echo "Your current level is <strong>".$_SESSION['level']."</strong> (".$_SESSION['level_name'].").<br \>";
		echo "The required level level is <strong>".$req_lvl."</strong> (".level_name($req_lvl).").<br \>";
		return false;
	}
}
And here is how I call it:

Code: Select all

//some code up here
if(check_level($perm_post_news)){
    //post the news
Is there some kind of extern command in PHP like in C++?

____________________________________

Also, I mind as well say this in this post instead of taking up 2 posts:
I love this site. I just found it today and I love how you guys totally tricked out phpBB like a car or something..!

____________________________________

If you can help me, thanks in advance!
Last edited by xjake88x on Sun Aug 01, 2004 7:29 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is header.php included before postnews.php? is the function in a class?
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post by xjake88x »

Header.php is included first.
index.php looks something like:

Code: Select all

<?
include("header.php");
?>
The function is not in a class, it's just declared at the top of header.php.
header.php looks something like:

Code: Select all

<?
session_start();
header("Cache-control: private");

function check_level($req_lvl){
	if($_SESSION['level']>=$req_lvl){
		return true;
	}else{
		echo "You lack permission to use access this page.<br />";
		echo "Your current level is <strong>".$_SESSION['level']."</strong> (".$_SESSION['level_name'].").<br \>";
		echo "The required level level is <strong>".$req_lvl."</strong> (".level_name($req_lvl).").<br \>";
		return false;
	}
}

function level_name($level){
	switch($level){
		case 1:
			return "Member";
			break;
		case 2:
			return "Moderator";
			break;
		case 3:
			return "Administrator";
			break;
	}
	return "Unknown";
}
//etc...
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post by xjake88x »

Wow am I stupid! Sorry, I figured this out. The "post news" link was going to postnews.php and not index.php?page=postnews.. Sorry to bother you :(.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

easy mistake :)
Post Reply