I am looking to create a function that I can easily call on any page required.
Usually I would use the following code to check if a user is logged in:
if($loggedin != ""){
echo('yes');
} else {
echo('no');
}
I would use the following code to check if a user is an admin:
$query="SELECT * FROM users WHERE username='$username' AND id='$userid' AND amin=1";
//if amin = 1 then they are an admin
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num==0) {
echo('no admin');
} else {
echo('admin');
}
I would like a function for both scripts. The first function should check if the user is logged in, if so display the rest of the page and if they are not logged in display an error message. The second function should check if the user is an admin, if so display the rest of the page and if not display an error.
Thanks for your time.