Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. LOGIN.PHP
  2. _________________
  3.  
  4.  
  5. <?php
  6. session_start();
  7. error_reporting(0);
  8.  
  9. if($_SESSION['logged_in']==true){
  10.     header('Location: index.php?action=already_logged_in');
  11. }
  12. ?>
  13. <html>
  14.     <head>
  15.         <title>Login</title>
  16.         <link type="text/css" rel="stylesheet" href="css/style.css" />
  17.     </head>
  18. <body>
  19.  
  20. <div id="loggain">
  21.  
  22.     <?php
  23.     if($_GET['action']=='not_yet_logged_in'){
  24.         echo "<div id='infoMesssage'>Du kan inte gå till index.php för att du är inte inloggad</div>";
  25.     }
  26.      
  27.     if($_POST){
  28.        
  29. $handle = fopen("!SÖKVÄG TILL TEXTFIL HÄR! t.ex. C:\\temp\\test.txt", "r");
  30. if ($handle) {
  31.     $slackerEno = 0;
  32.     $userArray;
  33.     while (($line = fgets($handle)) !== false) {
  34.         $userArray[i] = $line;
  35.         slackerEno++;
  36.     }
  37.  
  38.     fclose($handle);
  39. } else {
  40.     // error opening the file.
  41. }
  42.         $username = $userArray[0];
  43.         $password = $userArray[1];
  44.          
  45.         if($_POST['username']==$username && $_POST['password']==$password){
  46.              
  47.             $_SESSION['logged_in'] = true;
  48.              
  49.             header('Location: index.php');
  50.              
  51.         }else{
  52.             echo "<div>Fel användarnamn eller lösenord </div>";
  53.         }
  54.     }
  55.     ?>
  56.  
  57.     <form action="login.php" method="post">
  58.      
  59.         <div id="formTitel">Login</div>
  60.          
  61.         <div id="form">
  62.             <div >
  63.                 <input type="text" name="username" placeholder="Användarnamn" required autofocus />
  64.             </div>
  65.              
  66.             <div >
  67.                 <input type="password" name="password" placeholder="Lösenord" required autofocus/>
  68.             </div>
  69.          
  70.             <div>
  71.                 <input type="submit" value="Login" />
  72.             </div>
  73.         </div>
  74.           <div>
  75.             <a href="index.php">Gå till index </a>
  76.         </div>
  77.        
  78.     </form>
  79.      
  80. </div>
  81.  
  82. </body>
  83. </html>
  84.  
  85.  
  86.  
  87.  
  88. INDEX.PHP
  89. _______________________________________
  90.  
  91.  
  92. <?php
  93. session_start();
  94. error_reporting(0);
  95.  
  96. if(empty($_SESSION['logged_in'])){
  97.  
  98.     header('Location: login.php?action=not_yet_logged_in');
  99. }
  100. ?>
  101. <html>
  102.     <head>
  103.     <title>Inloggningen lyckades!</title>
  104.     <link type="text/css" rel="stylesheet" href="css/style.css" />
  105.     </head>
  106. <body>
  107.  
  108. <?php
  109.  
  110. $action = $_GET['action'];
  111.  
  112. if($action=='logout'){
  113.     session_destroy();
  114.     header('Location: login.php');
  115. }
  116.  
  117. else if($action=='already_logged_in'){
  118.     echo "<div id='infoMesssage'>Du kan inte logga in, du är redan inloggad!</div>";
  119. }
  120. ?>
  121.  
  122. <!-- some contents on our index page -->
  123. <div id='successMessage'>Du är inloggad :)</div>
  124. <div id='actions'>
  125.     <a href='index.php?action=logout'>Logout?</a> | <a href='login.php'>Gå till loggin page</a>
  126. </div>
  127.  
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement