Guest User

Untitled

a guest
Dec 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. $localhost = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $db = "login";
  6.  
  7. $conn = mysql_connect($localhost, $username, $password);
  8.  
  9. if(! $conn )
  10. {
  11. die('Could not connect: ' . mysql_error());
  12. }
  13.  
  14. if($conn )
  15. {
  16. echo "Uspjesno spajanje na bazu! <br /><br />";
  17. }
  18. mysql_select_db($db);
  19.  
  20. session_start();
  21. if(isset($_POST['submit']))
  22. {
  23.  
  24. if(!empty($_POST['user']) && !empty($_POST['pass']))
  25. {
  26.  
  27. $user=$_POST ['user'];
  28. $pass=$_POST ['pass'];
  29. $select="select * from users where username='$user' && password='$pass'";
  30. $sql=mysql_query($select) or die(mysql_error());
  31.  
  32. if(mysql_num_rows($sql)==1 )
  33. {
  34. echo "Login";
  35. $_SESSION['user'] = $user;
  36. header('location: welcome.php');
  37. }
  38. else {
  39. echo "Can't Login";
  40. }
  41. }
  42. }
  43. if (isset($_GET['logout'])){
  44.  
  45. session_unregister('username');
  46. }
  47.  
  48. ?>
  49.  
  50.  
  51.  
  52.  
  53. <html>
  54. <head>
  55.  
  56. </head>
  57.  
  58. <body>
  59.  
  60. <form method="post" action="login.php">
  61. Username: <input type="text" name="user" id="user" /> <br /> <br />
  62. Password: <input type="password" name="pass" id="pass" /> <br /> <br />
  63. <input type="submit" name="submit" value="Log In" />
  64.  
  65. </body>
  66.  
  67.  
  68. </html>
Add Comment
Please, Sign In to add comment