Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.97 KB | None | 0 0
  1. //INDEX
  2.  
  3. <html>
  4.  
  5.     <form action='login.php' method='POST'>
  6.         Username: <input type='text' name='username'><br>
  7.         Password: <input type='password' name='password'><br>
  8.         <input type='submit' value='Log in'>
  9.     </form> <p>
  10.    
  11.     <a href='register.php'>Register?</a>
  12.  
  13. </html>
  14.  
  15. //LOGIN
  16. <?php
  17.  
  18. session_start();
  19.  
  20. $username = $_POST['username'];
  21. $username = $_POST['password'];
  22.  
  23. if ($username&&$password)
  24.  
  25. {
  26.  
  27. $connect = mysql_conncet("localhost","root","") or die ("Couldn't connect!");
  28. mysql_select_db ("login") or die ("couldn't find db");
  29.  
  30. $query = mysql_query("SELECT * FROM users WHERE username='$username'");
  31.  
  32.  
  33. $numrows = mysql_num_rows($query);
  34.  
  35. if ($numrows!=0)
  36. {
  37.     while ($row =mysql_fetch_assoc($query))
  38.     {
  39.         $dbusername = $row ['username'];
  40.         $dbpassword = $row ['password'];
  41.     }
  42.    
  43.     //check to see if they match!
  44.     if ($username==$dbusername&&$password==$dbpassword)
  45.     {
  46.         echo "You're in!<a href='member.php'>Click</a> here to enter the memberpage";
  47.         $_SESSION['username']=$username;
  48.          
  49.        
  50.     }
  51.     else
  52.         echo "Incorrect password!";
  53. }
  54. else
  55.     die ("That user doesen't exsist!");
  56.    
  57. }
  58. else
  59.     die("Please enter username and a password!");
  60.    
  61.    
  62.    
  63. ?>
  64.  
  65.  
  66. //LOGOUT
  67.  
  68. <?php
  69.  
  70. sessoin_start();
  71.  
  72. session_destroy();
  73.  
  74. echo "You've been loggged out. <a href='index.php'>Click</a> here to return";
  75.  
  76.  
  77.  
  78.  
  79. ?>
  80.  
  81. //MEMBER
  82.  
  83. <?php
  84.  
  85. session_start();
  86.  
  87. if ($_SESSION['username'])
  88.     echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";
  89.     else
  90.         die("You must be logged in!");
  91. ?>
  92.  
  93. //REGISTER
  94.  
  95. <?php
  96. echo "<h1>Register</h1>";
  97.  
  98. $submit = $_POST['sumbit'];
  99.  
  100. $fullname = strip_tags ($_POST['fullname']);
  101. $username = strip_tags ($_POST['username']);
  102.  
  103. $password = strip_tags($_POST['password']);
  104. $repeatpassword =strip_tags ($_POST['repeatpassword']);
  105. $date = date ("y-m-d");
  106.  
  107. if ($submit)
  108.  
  109.  
  110. //check for existance
  111. if ($fullname&&$username&&$password&&$repeatpassword)
  112. {
  113.    
  114.    
  115.     if ($password==$repeatpassword)
  116.     {
  117.    
  118.         //check char length of username and fullname
  119.         if (strlen($username)>25||strlen($fullname)>25)
  120.         {
  121.         echo "Length of username or fullname is too long!";
  122.     }
  123.     else
  124.     {
  125.    
  126.         //check password length
  127.         if (strlen($password)>25 || strlen($password)<6)
  128.     {
  129.             echo "Password must be between 6 and 25 characteres";
  130.     }
  131.         else
  132.     {  
  133.             //register the user!
  134.            
  135.             //encrypt password
  136.             $passsword = md5($password);
  137.             $repeatpassword = md5 ($repeatpassword);
  138.            
  139.             //open datatbase
  140.             $connect =mysql_connect ("localhost","root","");
  141.             mysql_selelct_db("login"); //select database
  142.            
  143.             $queryreg = mysql_query("
  144.            
  145.             INSERT INTO users VALUES ('','$fullname','$username','$password','$date')
  146.            
  147.             ");
  148.            
  149.             echo ("You have been registered!<a href='index.php';>Return to login page</a>");
  150.        
  151.     }
  152.     }
  153.         echo "Please fill in <b>all</b> fields!";
  154.  
  155.  
  156. }
  157. }
  158.  
  159.  
  160. ?>
  161.  
  162. <html>
  163.  
  164. <form action='register.php' method='POST'>
  165.     <table>
  166.             <tr>
  167.                 <td>
  168.                 Full Name:
  169.                  </td>
  170.                 <td>
  171.                 <input type='text' name='fullname' value='<?php echo $fullname; ?>'>
  172.                
  173.                 </td>
  174.             </tr>
  175.             <tr>
  176.                 <td>
  177.                 Choose a username:
  178.                  </td>
  179.                 <td>
  180.                 <input type='text' name='username'value='<?php echo $username; ?>'>
  181.                
  182.                 </td>
  183.             </tr>
  184.             <tr>
  185.                 <td>
  186.                 Choose a password:
  187.                 </td>
  188.                 <td>
  189.                 <input type='password' name='password'>
  190.                
  191.                 </td>
  192.             </tr>
  193.             <tr>
  194.                 <td>
  195.                 Repeat your password:
  196.                 </td>
  197.                 <td>
  198.                 <input type='password' name='repeatpassword'>
  199.                
  200.                 </td>
  201.             </tr>
  202.      </table>
  203.      <p>
  204.      <input type='submit' name='submit' value='Register'>  
  205. </form>
  206.  
  207.  
  208. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement