daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Jul 20th, 2017 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $conn = mysql_connect('localhost', 'engodstartsamme', 'XXXXXXXXX') or die(mysql_error());
  4. mysql_select_db('engodstartsamme', $conn);
  5.  
  6. ?>
  7. <?
  8. if(isset($_SESSION['user_id'])) {
  9.  
  10.     // User is logged in!
  11.     $query = mysql_query("SELECT id, username, access FROM login
  12.                    WHERE ID = " . $_SESSION['user_id'] . " LIMIT 1")
  13.                    or die(mysql_error());
  14.  
  15. $access = mysql_fetch_array($query);
  16.  
  17. echo 'hej';
  18.  
  19. }else{
  20.    
  21. echo '<div id="topright"><img src="images/brugerlogin.png" id="brugerIMG"/>
  22. <div id="form"><form action="index.php?try=true" method="post" name="loginyeah"><input type="text" id="usernameForm" name="username" /><input type="password" id="passwordForm" name="password" /></div>
  23. <a href="javascript: submitform()"><img src="images/login.png" id="loginBTN"/></a></form></div>';
  24.  
  25. }
  26.  
  27. echo '<script type="text/javascript">
  28. function submitform()
  29. {
  30.  document.loginyeah.submit();
  31. }
  32. </script>';
  33.  
  34. // Check if user wants to login (GET info)
  35. if(isset($_GET['try'])) {
  36.  
  37.     // That's nice, user wants to login. But lets check if user has filled in all information
  38.     if(empty($_POST['username']) OR empty($_POST['password'])) {
  39.  
  40.         // User hasn't filled it all in!
  41.         echo '<font color="#810000"><b><u>Fejl:</u>Udfyld venligst alle felterne</b></font><br /><br />';
  42.  
  43.     } else {
  44.  
  45.         // User filled it all in!
  46.  
  47.         // Make variables save with mysql_real_escape_string and md5
  48.         $username = mysql_real_escape_string($_POST['username']);
  49.         $password = md5($_POST['password']);
  50.  
  51.         // Search for a combination
  52.         $query = mysql_query("SELECT ID FROM login
  53.                        WHERE username = '" . $username . "'
  54.                        AND password = '" . $password . "'
  55.                       ") or die(mysql_error());
  56.  
  57.         // Save result
  58.         list($user_id) = mysql_fetch_row($query);
  59.  
  60.         // If the user_id is empty no combination was found
  61.         if(empty($user_id)) {
  62.  
  63.             echo '<div id="loggetind2"><font color="#616161">Brugernavn eller password er ikke korrekt.</font></div>';
  64.  
  65.         } else {
  66.  
  67.             // the user_id variable doesn't seem to be empty, so a combination was found!
  68.  
  69.             // Create new session, store the user id
  70.             $_SESSION['user_id'] = $user_id;
  71.  
  72.             // Redirect to userpanel.php
  73.             header('location: index.php');
  74.  
  75.         }      
  76.  
  77.     }
  78.  
  79. }
  80. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top