Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.56 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="pl">
  3. <head>
  4.  
  5.     <meta charset="utf-8" />
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  7.     <title>grammo</title>
  8.    
  9.     <meta name="description" content="mmo" />
  10.     <meta name="keywords" content="mmo" />
  11.    
  12.     <link href="" rel="stylesheet" type="text/css" />
  13.     <link href="" rel="stylesheet" type="text/css" />
  14.    
  15. </head>
  16. <body>
  17.  
  18. <?php
  19. header('refresh: ; url=http://localhost'); // Przekierowanie strony + odświeżenie
  20. ?>
  21. <?php
  22.  
  23. ?>
  24.  
  25.  
  26. <?php
  27.     $page = $_GET['action'];
  28.     if(is_null($page)) {
  29.         $page = $_POST['action'];
  30.     }
  31.    
  32.     if($page == "login") {
  33.        
  34.     }
  35.    
  36.     if($page == "register") {
  37.        
  38.     }
  39. ?>
  40.  
  41. <?php if($page == "login"): ?>
  42. <form method="POST" action="">
  43.     <input type="hidden" name="action" value="login" />
  44.     <input type="text" name="user_login" value="" placeholder="login..." /> <br/>
  45.     <input type="password" name="user_pass" value="" placeholder="haslo..." /> <br/>
  46.     <input type="submit" value="Loguj" />
  47. </form>
  48. <?php elseif($page == "register"): ?>
  49. <form method="POST" action="">
  50.     <input type="hidden" name="action" value="register" />
  51.     <input type="text" name="user_login" value="" placeholder="login..." /> <br/>
  52.     <input type="password" name="user_pass_01" value="" placeholder="haslo..." /> <br/>
  53.     <input type="password" name="user_pass_02" value="" placeholder="powtorz haslo..." /> <br/>
  54.     <input type="text" name="user_email" value="" placeholder="e-mail..." /> <br/>
  55.     <input type="submit" value="Rejstruj" />
  56. </form>
  57. <?php endif; ?>
  58.  
  59.  
  60.  
  61. <?php
  62.     $servername = 'localhost';
  63.     $username = 'root';
  64.     $password = '';
  65.     $dbname = 'players';
  66.  
  67.     $page = $_GET['action'];
  68.     if(is_null($page)) {
  69.         $page = $_POST['action'];
  70.     }
  71.    
  72.     if($page == "login") {
  73.        
  74.     }
  75.    
  76.     if($page == "register") {
  77.         if ($_SERVER['REQUEST_METHOD'] === 'POST') {   
  78.            
  79.             $login = trim(strip_tags($_POST['user_login']));
  80.             $password1 = trim(strip_tags($_POST['user_pass_01']));
  81.             $password2 = trim(strip_tags($_POST['user_pass_02']));
  82.             $email = trim(strip_tags($_POST['user_email']));
  83.            
  84.             if($password1 != $password2) {
  85.                 die("Passwords are different");
  86.             }
  87.            
  88.             $conn = new mysqli($servername, $username, $password, $dbname);
  89.             // Check connection
  90.             if ($conn->connect_error) {
  91.                 die("Connection failed: " . $conn->connect_error);
  92.             }
  93.            
  94.             $sql = "INSERT INTO players (login, pass, email) VALUES ('".$login."', '".md5($password1)."', '".$email."')";
  95.  
  96.             if ($conn->query($sql) === TRUE) {
  97.                 $result = array('status' => 1, 'msg' => "Success");
  98.             } else {
  99.                 $result = array('status' => 0, 'msg' => $conn->error);
  100.                
  101.             }
  102.            
  103.             echo json_encode($result);
  104.             $conn->close();
  105.             die;
  106.         }
  107.        
  108.    
  109.     if ($_SERVER['REQUEST_METHOD'] === 'POST') {   
  110.    
  111.     $login = trim(strip_tags($_POST['user_login']));
  112.     $passwd = trim(strip_tags($_POST['user_pass']));
  113.    
  114.     $conn = new mysqli($servername, $username, $password, $dbname);
  115.    
  116.     if ($conn->connect_error) {
  117.         die("Connection failed: " . $conn->connect_error);
  118.     }
  119.    
  120.     $sql = "SELECT * FROM players WHERE login LIKE '" . $login . "'";
  121.     $result = $conn->query($sql);
  122.    
  123.     if ($result->num_rows > 0) {
  124.         $user = $result->fetch_assoc();
  125.        
  126.         if(md5($passwd) != $user['pass']) {
  127.             $result = array('status' => 0, 'msg' => "Wrong Password");
  128.         } else {
  129.             $result = array('status' => 1, 'msg' => "Success!");
  130.         }          
  131.     } else {
  132.         $result = array('status' => 0, 'msg' => "There is no such user");
  133.     }
  134.    
  135.     echo json_encode($result);
  136.     $conn->close();
  137.     die;
  138. }
  139. ?>
  140.  
  141. <br/>
  142. <a href="?action=register">Register</a> |
  143. <a href="?action=login">Login</a>
  144. </body>
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement