droidus

Untitled

Aug 6th, 2011
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.06 KB | None | 0 0
  1. <?php
  2. if (!isset($_SESSION))
  3.     {
  4.         session_start();
  5.     }
  6. if(isset($_SESSION['admin']))
  7.     {
  8.         header('Location: users/admin/index.php');
  9.         exit();
  10.     }
  11. require_once('../Connections/uploader.php');
  12. function loginFormErrorsCheck ($loginUsername, $loginPassword) {
  13.   if (empty($loginUsername) || empty($loginPassword)) {
  14.     return true;
  15.   } else {
  16.     return false;
  17.   }
  18. }
  19. ?>
  20. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  21. <html xmlns="http://www.w3.org/1999/xhtml">
  22. <head>
  23. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  24. <title>Admin Center Login</title>
  25. <link href="css/styles.css" rel="stylesheet" type="text/css" />
  26. <style type="text/css">
  27. .required { color:#F00;
  28. }
  29. body {
  30.     background-color: #FC9;
  31.     font-family:helvetica;
  32. }
  33. </style>
  34. </head>
  35.  
  36. <body>
  37.  
  38. <?php
  39. if (isset($_POST['login'])) {
  40.        
  41.     $loginUsername = $_POST['uname'];  
  42.     $loginPassword = $_POST['pword'];
  43.    
  44.     $blank_fields = loginFormErrorsCheck ($loginUsername, $loginPassword);  
  45.        
  46.     if (!$blank_fields) {
  47.         $loginPassword = md5($loginPassword);
  48.                
  49.         mysql_select_db($database_uploader, $uploader);    
  50.         $query = "SELECT * FROM members WHERE uname='"
  51.         . mysql_real_escape_string($loginUsername) .
  52.         "' AND pword='" . mysql_real_escape_string($loginPassword) . "'";  
  53.         $result = mysql_query($query) or die(mysql_error());
  54.                
  55.         // make sure the username and password were found
  56.         if (mysql_num_rows($result) > 0) {
  57.             $row = mysql_fetch_array($result) or die(mysql_error());
  58.             mysql_close($result);
  59.            
  60.             if ($loginUsername == "admin") { // Admin Login
  61.                 $_SESSION['admin'] = "Admin.";
  62.                 header('Location: users/admin/index.php');
  63.                 exit;
  64.             } else {
  65.                 echo "You cannot login to this area.  Please <a href='portal.php'>go to the portal</a> to login.";
  66.                 header('Location: portal.php');
  67.                 die();
  68.             }
  69.         }
  70.         else {$login_errors[] = "Please check your User ID and Password, and try again.";}
  71.     } else { $login_errors[] = "<div class='error'><img src='../Images/error_image.png' width='16' height='16' /> <b>Error</b>: Please fill in all fields.</div>"; }
  72. }
  73.  
  74. // Begin IP logging
  75. if ($_SERVER['SERVER_ADDR'] != "...") {
  76.    
  77. $filename = 'logs/logIP.txt';
  78.  
  79. $somecontent = "\n" . $_SERVER['SERVER_ADDR'] . " - " .   date("F j, Y, g:i a");
  80.  
  81. // Let's make sure the file exists and is writable first.
  82. if (is_writable($filename)) {
  83.  
  84.     if (!$handle = fopen($filename, 'a')) {
  85.          echo "Cannot open file.";
  86.          exit;
  87.     }
  88.     if (fwrite($handle, $somecontent) === FALSE) {
  89.         echo "Cannot write to file.";
  90.         exit;
  91.     }
  92.  
  93.     echo "Your IP address has been recorded for security purposes.";
  94.  
  95.     fclose($handle);
  96.  
  97. } else {
  98.     echo "The file is not writable.";
  99. }
  100. }
  101. ?>
  102.  
  103. <?php
  104. if (isset($login_errors) && !empty($login_errors)) {
  105.     $result = count($login_errors);
  106.    
  107.     for ($i=0; $i<$result; $i++) {
  108.         echo "<p class='errors'>$login_errors[$i]<br></p>";  
  109.     }
  110. }
  111. ?>
  112.  
  113. <table width="50%" border="1" align="center">
  114.   <tr>
  115.     <td><form action="" method="post" id="login" name="login" >
  116. <table border="0" align="center" cellpadding="3">
  117.   <tr>
  118.     <td colspan="2"><h3>RESTRICTED ACCESS FOR PERSONEL ONLY</h3>
  119.       <p>If you are not an administrator of this website, you must leave this page now. If you are looking for the standard login member portal, please <a href="portal.php">click here</a>.
  120.       <p><strong>Your IP address, <? echo $_SERVER['REMOTE_ADDR'] ?>, has been logged.</strong></p></td>
  121.     </tr>
  122.   <tr>
  123.     <td>User ID: </td>
  124.     <td><input type="text" name="uname" id="uname" value="<? if (isset($login_errors)) {echo $_POST['uname'];} ?>" /></td>
  125.   </tr>
  126.   <tr>
  127.     <td>Password: </td>
  128.     <td><input name='pword' type='password' value="<? if (isset($login_errors)) {echo $_POST['pword'];} ?>" /></td>
  129.   </tr>
  130.     <tr>
  131.       <td>&nbsp;</td>
  132.       <td><input type="submit" name="login" id="login" value="Log me In!" /></td>
  133.     </tr>
  134. </table>
  135. </form></td>
  136. </tr></table>
  137. </body>
  138. </html>
Advertisement
Add Comment
Please, Sign In to add comment