Advertisement
Guest User

Code option programmation - Théotime Rigaut

a guest
Mar 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <body>
  4.     <form method="POST">
  5.     <p>Login : <input type='text' name='login' value='login'/></p>
  6.     <p>Password : <input type='password' name='password' value='*****'/></p>
  7.     <input type="submit" name="submit" value="Submit"/>
  8.     </form>
  9.     <p>Not signed up yet ? <a href=register.php>Register</a>.</p>
  10.         <?php
  11.         $wrong_user=false;
  12.         $wrong_password=false;
  13.             if(isset($_POST["submit"]) && $_POST["submit"]=="Submit" && isset($_POST['login']) and isset($_POST['password'])){
  14.                 $handle=fopen("logs/logins.txt", "r+");
  15.                     while (!feof($handle)){
  16.                         $line=fgets($handle);
  17.                         explode('\t',$line);
  18.                         if ($_POST['login']==$line[0]) {
  19.                             if ($_POST['password']==$line[1]) {
  20.                                 $match=true;
  21.                             }
  22.                             else {
  23.                                 $match=false;
  24.                                 $wrong_password=true;
  25.                             }
  26.                         }
  27.                         else{
  28.                             $match=false;
  29.                             $wrong_user=true;
  30.                         }
  31.                     }
  32.                 if ($match==true) {
  33.                     session_start();
  34.                     $_SESSION['login']=$_POST['login'];
  35.                     print "Login successful!";
  36.                     print "<p><a href=\"welcome.php\" target=\"_blank\">Jump to the website</a></p>";
  37.                 }
  38.                 else {
  39.                     if ($wrong_password=true) {
  40.                         print "Wrong password." ;
  41.                         }
  42.                     if ($wrong_user=true) {
  43.                         print "Unknown username." ;
  44.                         }
  45.                 }
  46.             }
  47.             else {
  48.                 print "Please specify username and login." ;
  49.             }
  50.         ?>
  51.     </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement