Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. <?php
  2. include 'common.php';
  3. session_start();
  4. $sn = session_id();
  5. $expire_period = time()+60*60;
  6. //$login_success = false;
  7. if(isset($_COOKIE['login_success'])){
  8. if ($_COOKIE['login_success']==true && !isset($_GET['logout'])){
  9. $extra = "store.php?s=".$sn;
  10. header("Location: ".directoryURL($extra));
  11.  
  12. }
  13.  
  14. }
  15.  
  16. if(isset($_POST['loginName'])){
  17. $loginName = $_POST['loginName'];
  18. $pw = $_POST['pw'];
  19.  
  20. //MySQL
  21. include 'mysqlQuery.php';
  22. $connet=mysqlConnect();
  23. //check login Name
  24. $query = "SELECT pw FROM users WHERE loginName='".$loginName."';";
  25. $rs=mysqlQuery($query,$connet);
  26. $errMsg = $errMsg . mysql_error();
  27. $pws = mysql_fetch_row($rs);
  28. $rpw = $pws[0];
  29. mysqlClose($connet);
  30. //end my SQL
  31.  
  32. setcookie("login_success", false, $expire_period);
  33. if($pw == $rpw){
  34. //$login_success = true;
  35. setcookie("login_success", true, $expire_period);
  36. setcookie("login_time", date(DATE_COOKIE), $expire_period);
  37. setcookie("session_id", $sn, $expire_period);
  38. $_SESSION['loginName']=$loginName;
  39. $extra = "store.php?s=".$sn;
  40. header("Location: ".directoryURL($extra));
  41. exit();
  42. }
  43. else{
  44. header( "Location:".$_SERVER['PHP_SELF']."?error=1");
  45. //echo "fail";
  46. }
  47. }
  48.  
  49. if(isset($_GET['logout'])){
  50. setcookie("login_success", '', time()-3600);
  51. setcookie("login_time", '', time()-3600);
  52. setcookie("session_id", '', time()-3600);
  53. //header( "Location:".$_SERVER['PHP_SELF'] );
  54. //exit();
  55. }
  56. ?>
  57. <html>
  58. <header>
  59. <title>Dressing Online Shop</title>
  60. <link rel="stylesheet" href="css/style.css" type="text/css" />
  61. <script type="text/javascript" src="./js/form_login.js"></script>
  62. <script type="text/javascript">
  63. function display(index) {
  64. var xmlhttp = new XMLHttpRequest();
  65. xmlhttp.onreadystatechange=function() {
  66. if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  67. document.getElementById("imageDiv").innerHTML=xmlhttp.responseText;
  68. }
  69. };
  70. xmlhttp.open("GET", "advertisement.php", true);
  71. xmlhttp.send();
  72. index = (index + 1) % 3;
  73. setTimeout("display(" + index + ")", 3000);
  74. }
  75.  
  76.  
  77. </script>
  78. </header>
  79. <body onLoad="display(0)">
  80.  
  81. <div align="center" class="header">
  82. Welcome to<br> Dressing Online Shop
  83. <img src = "fashion.jpg"/>
  84. </div>
  85.  
  86. <div align="center">
  87.  
  88. <p class = "description">Please login to continue <a href="registration.php">New User?</a> </p>
  89.  
  90. <form name="frm_login" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  91. <table width="500" border="0" cellspacing="5" cellpadding="5">
  92. <tr>
  93. <td rowspan="3" scope="col"><div align="center" id="imageDiv" ></div></th>
  94. <td id="lgn">Username : </td>
  95. <td><input name="loginName" type="text"></td>
  96. </tr>
  97. <tr>
  98. <td id="pw" >Password : </td>
  99. <td><input name="pw" type="password"></td>
  100. </tr>
  101. <tr>
  102. <td><input type="submit" value="Login" onClick="return validate()"></td>
  103. <td><?php
  104. if(isset($_GET['error'])){
  105. echo "Wrong Login name or password.";
  106. }
  107. if(isset($_GET['logout'])){
  108. echo "You have logged out sucessfully.";
  109. }
  110. ?></td>
  111. </tr>
  112. </table>
  113. </form>
  114. </div>
  115. </body>
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement