Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. <?php
  2. include('includes/database.php');
  3. $error = '';
  4. // username and password sent from form
  5. if(isset($_POST['submit']))
  6. {
  7. if(isset($_POST['myusername']) && isset($_POST['mypassword']))
  8. {
  9. $myusername = $_POST['myusername'];
  10. $mypassword = $_POST['mypassword'];
  11. // To protect MySQL injection (more detail about MySQL injection)
  12. $myusername = stripslashes($myusername);
  13. $mypassword = stripslashes($mypassword);
  14. $myusername = mysqli_real_escape_string( $mysqli,$myusername);
  15. $mypassword = mysqli_real_escape_string($mysqli,$mypassword);
  16. $mypassword = md5($mypassword);
  17. $sql = "SELECT * FROM members WHERE username='$myusername' and
  18. password='$mypassword'";
  19. $result = mysqli_query( $mysqli, $sql);
  20. // Mysql_num_row is counting table row
  21. $rowcount = mysqli_num_rows($result);
  22.  
  23. // If result matched $myusername and $mypassword, table row must be 1 row
  24. if($rowcount == 1){
  25. // Register $myusername, $mypassword and redirect to file "index.php"
  26. session_start();
  27. $_SESSION['myusername'] = $myusername;
  28. $_SESSION['mypassword'] = $mypassword;
  29. header("location:index.php");
  30. }
  31. else {
  32. $error = "Wrong Username or Password!";
  33. }
  34. }
  35. else
  36. {
  37. $error = "Please provide Username and/or Password!";
  38. }
  39. }
  40. ?>
  41. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  42. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  43. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  44. <head>
  45. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  46. <meta name="description" content="" />
  47. <meta name="keywords" content="" />
  48. <meta name="author" content="" />
  49. <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
  50. <title>1stWebDesigner PHP Template</title>
  51. <script language="javascript">
  52. function validate(){
  53. var f=document.login;
  54. var error = false;
  55. // preverjati pricnemo na koncu, da pride potem focus na prvo manjkajoce polje od zgoraj!
  56. if(f.mypassword.value==''){
  57. document.getElementById("password_error").style.color="red";
  58. f.mypassword.focus();
  59. error = true;
  60. }
  61. else
  62. {
  63. document.getElementById("password_error").style.color="#f8f8f8";
  64. }
  65. if(f.myusername.value==''){
  66. document.getElementById("username_error").style.color="red";
  67. f.myusername.focus();
  68. error = true;
  69. }
  70. else
  71. {
  72. document.getElementById("username_error").style.color="#f8f8f8";
  73. }
  74. if(error)
  75. return false;
  76. //f.command.value='update';
  77. f.submit();
  78. }
  79. </script>
  80. </head>
  81. <body>
  82. <div id="wrapper">
  83. <div id="header">
  84. <?php include('includes/header.php'); ?>
  85. </div> <!-- end #header -->
  86. <div id="content">
  87. <br/>
  88. <br/>
  89. <table width="300" border="0" align="center" cellpadding="0"
  90. cellspacing="1" >
  91. <tr>
  92. <form name="login" method="post" action="<?php
  93. echo($_SERVER['PHP_SELF']) ?>">
  94. <td>
  95. <table width="100%" border="0" cellpadding="3"
  96. cellspacing="1" bgcolor="#FFFFFF">
  97. <tr>
  98. <td colspan="3"><strong>Member Login </strong></td>
  99. </tr>
  100. <tr>
  101. <td width="78">Username</td>
  102. <td width="6">:</td>
  103. <td width="294"><input name="myusername" type="text"
  104. id="myusername"></td>
  105. </tr>
  106. <tr>
  107. <td>Password</td>
  108. <td>:</td>
  109. <td><input name="mypassword" type="password"
  110. id="mypassword"></td>
  111. </tr>
  112. <tr>
  113. <td>&nbsp;</td>
  114. <td>&nbsp;</td>
  115. <td><input type="submit" name="submit" value="Login"></td>
  116. </tr>
  117. <tr>
  118. <td>&nbsp;</td>
  119. <td>&nbsp;</td>
  120. <td><a href="register.php">Register</a>
  121. </tr>
  122. <tr>
  123. <td colspan="3" style="color:red;"><?php echo $error ?></td>
  124. </tr>
  125. </table>
  126. </td>
  127. </form>
  128. </tr>
  129. </table>
  130. <br/>
  131. <br/>
  132. </div> <!-- end #content -->
  133. <div id="footer">
  134. <?php include('includes/footer.php'); ?>
  135. </div> <!-- end #footer -->
  136. </div> <!-- end #wrapper -->
  137. </body>
  138. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement