Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why is my function echoing  a 1?

Posted on 2011-05-04
9
Medium Priority
?
193 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:FairyBusiness
9 Comments
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35691735
perhaps the 1 is in admin.php or public.php?
0
 
LVL 3

Expert Comment

by:wuyinzhi
ID: 35691785
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';

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 6

Accepted Solution

by:
cfEngineers earned 2000 total points
ID: 35691962
you are echoing the function

try in your account.txt

admin();

or change your function to just return the template to use

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

 then you could do this

include admin();
0
 
LVL 11

Expert Comment

by:mattibutt
ID: 35691964
Are you seeing 1?
0
 

Author Closing Comment

by:FairyBusiness
ID: 35691977
Yep that worked!  Still don't know why it was showing a 1 but thanks!
0
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35691990
which one did you end up doing?
0
 

Author Comment

by:FairyBusiness
ID: 35692001
this;

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


include admin();
0
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35692009
It was showing a 1 because anything returned other than a 0 in a function returned.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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