FairyBusiness
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';
}
}
}
}
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';
so maybe you should write:
return "include 'admin.php'";
rather than
return include 'admin.php';
ASKER
Nope I thought of that too:
http://auroriella.com/public.txt
http://auroriella.com/admin.txt
http://auroriella.com/account.txt
http://auroriella.com/public.txt
http://auroriella.com/admin.txt
http://auroriella.com/account.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you seeing 1?
ASKER
Yep that worked! Still don't know why it was showing a 1 but thanks!
which one did you end up doing?
ASKER
this;
if($key == 1) {
return 'admin.php';
}
else {
return 'public.php';
}
include admin();
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.