Advertisement
Guest User

Untitled

a guest
May 19th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. function db_login() {
  2.     $server = "server";
  3.     $username = "username";
  4.     $password = "password";
  5.    
  6.     global $link;
  7.    
  8.     $link = @mysql_connect ($server, $username, $password)
  9.     or die (mysql_error());
  10.  
  11.     if (!@mysql_select_db("database", $link)) {
  12.         echo "<p>There has been an error. This is the error message:</p>";
  13.         echo "<p><strong>" . mysql_error() . "</strong></p>";
  14.         echo "Please Contact Your Systems Administrator with the details";
  15.     }
  16. }
  17.  
  18. if ($_SESSION['logged_in'] == 1) {
  19.     echo "<a href=\"myaccount.php\">My Account</a><br />\n";
  20.    
  21.     // Check if the user is an admin
  22.     // If yes, display the 'Admin Panel' link
  23.    
  24.     $link = db_login();
  25.    
  26.     $user = $_SESSION['user'];
  27.    
  28.     $sql_check_admin = "SELECT admin FROM users WHERE (email = '$user')";
  29.    
  30.     $result = mysql_query($sql_check_admin, $link);
  31.     check_result($result);
  32.    
  33.     $row_admin = mysql_fetch_array($result);
  34.    
  35.     $admin = $row_admin['admin'];
  36.    
  37.     if ($admin == 1)
  38.         echo "<a href=\"/admin\">Admin Panel</a><br />";
  39.        
  40.     mysql_close($link);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement