Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. //file: login.php
  2.  
  3. ...
  4. if (!$_SESSION['username']) {
  5. ?>
  6.  
  7.  
  8. <br>
  9. <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  10. <tr>
  11. <form name="form1" method="post" action="checklogin.php">
  12. <td>
  13. <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  14. <tr>
  15. <td colspan="3"> <strong> Belépés </ strong> </ td>
  16. </ TR>
  17. <tr>
  18. <td width="78"> Felhasználó </ td>
  19. <td width="6">: </ td>
  20. <td width="294"><input name="myusername" type="text" id="myusername"></ td>
  21. </ TR>
  22. <tr>
  23. <td> jelszó </ td>
  24. <td>: </ td>
  25. <td><input name="mypassword" type="password" id="mypassword"></ td>
  26. </ TR>
  27. <tr>
  28. <td> </ td>
  29. <td> </ td>
  30. <td><input type="submit" name="Submit" value="Login"></ td>
  31. </TR>
  32. </Table>
  33. </Td>
  34. </Form>
  35. </TR>
  36. </table><br>
  37. <?
  38. }
  39. else {
  40.   print "Már be vagy jelentkezve<br>
  41.  kijelentkezés <a href="127.0.0.1/logout.php">kacc</a>";
  42. };
  43. ...
  44.  
  45.  
  46. /*-------------------------------------------*/
  47.  
  48. //file: checklogin.php
  49.  
  50. <?php
  51. require_once("config.php");
  52. require_once("connect.php");
  53. ob_start();
  54. $tbl_name="users"; // Table name
  55.  
  56. // Connect to server and select databse.
  57. mysql_connect("$mysql_host", "$mysql_user", "$mysql_pass")or die("cannot connect");
  58. mysql_select_db("$mysql_db")or die("cannot select DB");
  59.  
  60. // Define $myusername and $mypassword
  61. $myusername=$_POST['myusername'];
  62. $mypassword=md5($_POST['mypassword']);
  63.  
  64. // To protect MySQL injection (more detail about MySQL injection)
  65. $myusername = stripslashes($myusername);
  66. $mypassword = stripslashes($mypassword);
  67. $myusername = mysql_real_escape_string($myusername);
  68. $mypassword = mysql_real_escape_string($mypassword);
  69.  
  70. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  71. $result=mysql_query($sql);
  72.  
  73. // Mysql_num_row is counting table row
  74. $count=mysql_num_rows($result);
  75. // If result matched $myusername and $mypassword, table row must be 1 row
  76.  
  77. if($count==1){
  78. // Register $myusername, $mypassword and redirect to file "login_success.php"
  79. session_start();
  80. $_SESSION['username'] = $myusername;
  81. $_SESSION['password'] = $mypassword;
  82. $_SESSION['time'] = time();
  83. header("location:login_success.php");
  84. }
  85. else {
  86. echo "Wrong Username or Password";
  87. }
  88.  
  89. ob_end_flush();
  90. ?>
  91.  
  92.  
  93. /*-------------------------------------------*/
  94.  
  95. //file: login_succes.php
  96.  
  97. <?php
  98. session_start();
  99. if(!session_is_registered(myusername)){
  100. header("location:login.php");
  101. }
  102. $_SESSION["id"] = $id;
  103. $_SESSION["username"] = $myusername;
  104. $_SESSION["password"] = md5($_POST['mypassword']);
  105. $_SESSION["gmlevel"] = $gmlevel;
  106. ?>
  107.  
  108. <html>
  109. <body>
  110. Login Successful
  111. </body>
  112. </html>
  113. <?
  114. ?>
  115.  
  116. /*-------------------------------------------*/
  117.  
  118. //file: logout.php
  119.  
  120. <?
  121. session_start();
  122. session_destroy();
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement