Guest User

Untitled

a guest
Jan 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $mysqli = new mysqli('localhost', 'root', '', 'mybd');
  4.  
  5. if (mysqli_connect_errno()) {
  6. printf("Conexión fallida: %sn", mysqli_connect_error());
  7. exit();
  8. }
  9. if (isset($_GET['login'])) {
  10. if ($_GET['login'] == "true") {
  11. $query = "SELECT user,pass FROM usuarios WHERE user =";
  12. $query.= "'".$_GET['user']."'";
  13. $query.= " AND pass =";
  14. $query.= "'".$_GET['pass']."'";
  15. $res = $mysqli->query($query);
  16. if ($row = mysqli_fetch_array($res)) {
  17. if ($row['user'] == $_GET['user'] && $row['pass'] == $_GET['pass']) {
  18. $_SESSION['login'] = $_GET['user'];
  19. header("Location: http://".$_SERVER['HTTP_HOST']."/panel/panel.php");
  20. }else{
  21. session_unset();
  22. echo json_encode(array("text"=>"Datos erroneos, intentelo de nuevo."));
  23. }
  24. }
  25. }else{
  26. session_unset();
  27. unset($_SESSION['login']);
  28. header("Location: http://".$_SERVER['HTTP_HOST']."/panel/");
  29. }
  30. }
  31. ?>
  32.  
  33. function id(id){
  34. return document.getElementById(id);
  35. }
  36. function clase(clase){
  37. return document.getElementsByClassName(clase);
  38. }
  39. var form = id("loginform");
  40. form.addEventListener('submit',function(e){
  41. e.preventDefault();
  42. e.stopPropagation();
  43. var user = id("user").value;
  44. var pass = id("pass").value;
  45. var url = location.protocol+"//"+location.host+"/panel/login.php?login=true&user="+user+"&pass="+pass;
  46. xhr = new XMLHttpRequest();
  47. xhr.open('GET', url, true);
  48. xhr.onreadystatechange = function(response){
  49. if (xhr.readyState == 4 && xhr.status == 200) {
  50. if (response) {
  51. var data = JSON.parse(JSON.stringify(response.target.responseText));
  52. console.log(data);
  53. if (data.text) {
  54. id("resp").innerText = data.text;
  55. }
  56. }
  57. }
  58. };
  59. xhr.send();
  60. });
  61.  
  62. <!DOCTYPE html>
  63. <html lang="en">
  64. <head>
  65. <meta charset="UTF-8">
  66. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  67. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  68. <title>Document</title>
  69. </head>
  70. <body>
  71.  
  72. </body>
  73. </html>
Add Comment
Please, Sign In to add comment