Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

Why is my function echoing a 1?

I wrote this function to include a file according to who is a logged in (an admin or a regular user). Its working fine, but it puts a 1 at the end and it looks stupid.  Can anyone see why?

// sets admin privelages
function admin() {
	global $username, $hash_password, $conn, $message, $error;
	if(isset($_SESSION['user_id'])) {
		$user_id = $_SESSION['user_id'];
		$query = "SELECT admin "; // SECURITY --> Do not want to retrieve password 
		$query .= "FROM users ";
		$query .= "WHERE id=" . $user_id;
		$query .= " LIMIT 1";
		$result = mysql_query($query, $conn);
		confirm_query($result);
		while($data = mysql_fetch_array($result)) {
			// check to see if they have admin privelages turned on
			$key = $data['admin'];
			if($key == 1) {
				return include 'admin.php';
			}
			else {
				return include 'public.php';	
			}
		}
	}
}

Open in new window

Avatar of cfEngineers
cfEngineers

perhaps the 1 is in admin.php or public.php?
just guessing.. you mean the function should return string "include 'admin.php'" or "include 'public.php'" right?

so maybe you should write:

return "include 'admin.php'";

rather than

return include 'admin.php';

Avatar of FairyBusiness

ASKER

ASKER CERTIFIED SOLUTION
Avatar of cfEngineers
cfEngineers

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
Are you seeing 1?
Yep that worked!  Still don't know why it was showing a 1 but thanks!
which one did you end up doing?
this;

if($key == 1) {
                        return 'admin.php';
                  }
                  else {
                        return 'public.php';      
                  }


include admin();
It was showing a 1 because anything returned other than a 0 in a function returned.