Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: PHP  |  size: 2.25 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. $properly_filled_in = true;
  4.  
  5. function validateEmail()
  6. {
  7.     if(isset($_POST['email']))
  8.     {
  9.         if($_POST['email'] == "")
  10.         {
  11.             $properly_filled_in = false;
  12.             echo 'må fylles inn';
  13.         }
  14.         else if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $_POST['email']))
  15.         {
  16.             $properly_filled_in = false;
  17.             echo 'feil format på e-mail';
  18.         }
  19.     }
  20.     else
  21.     {
  22.         echo '*';
  23.     }
  24. }
  25.  
  26. function validatePassword()
  27. {
  28.     if(isset($_POST['password']))
  29.     {
  30.         if($_POST['password'] == "")
  31.         {
  32.             $properly_filled_in = false;
  33.             echo 'må fylles inn';
  34.         }
  35.         else if(strlen($_POST['password']) < 8)
  36.         {
  37.             $properly_filled_in = false;
  38.             echo 'passordet er for kort';
  39.         }
  40.     }
  41.     else
  42.     {
  43.         echo '*';
  44.     }
  45. }
  46.  
  47. ?>
  48.  
  49. <form action="?page=login" method="POST">
  50.     <div id="loginField">
  51.         <label for="email" class="label">E-mail</label>
  52.         <input type="text" name="email" class="justify textbox" />
  53.         <p id="emailValid" class="valid"><?php validateEmail(); ?></p>
  54.  
  55.         <label for="password"  class="label secondLabel">Passord</label>
  56.         <input type="password" name="password" class="justify textbox" />
  57.         <p id="passwordValid" class="valid"><?php validatePassword(); ?></p>
  58.  
  59.        
  60.         <div id="submit">
  61.             <a href="?page=registrer" id="registrer">Registrer bruker</a>
  62.             <input type="submit" class="button" id="submitButton" value="Logg inn" />
  63.         </div>
  64.     </div>
  65. </form>
  66.  
  67. <?php
  68.  
  69. if($properly_filled_in)
  70. {
  71.     $admin = new Admin($_POST);
  72.  
  73.     $sql = 'SELECT PERSON_ID AS person_id FROM ADMIN WHERE PASSWORD = "'.$admin->password.'" AND EMAIL = "'.prepare($admin->email).'";';
  74.     $query = mysql_query($sql) or die(mysql_error());
  75.  
  76.     if(mysql_affected_rows() == 1 && $res = mysql_fetch_array($query))
  77.     {
  78.         $res = mysql_fetch_array($query);
  79.         $_SESSION["person_id"] = $res["person_id"];
  80.         $success = true;
  81.  
  82.         echo '<p id="feedback">Du er nå logget inn.</p>';
  83.         include FRAGMENTS_PATH.'timeout.php';
  84.     }
  85. }
  86.  
  87. ?>