Advertisement
Guest User

Untitled

a guest
Aug 13th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <?php
  2.  
  3. include "connection.php";
  4.  
  5.  
  6. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  7.  
  8.    
  9.         $action = isset($_GET['action']) ? $_GET["action"] : null;
  10.         $username = isset($_GET['username']) ? $_GET["username"] : null;
  11.         $password =isset($_GET['password']) ? $_GET["password"] : null;        
  12.         $email =isset($_GET['email']) ? $_GET["email"] : null;
  13.  
  14.  
  15.    
  16.  
  17.   if($action == "Auth"){
  18.             if($username && $password){
  19.            
  20.             $sql = "SELECT * FROM user WHERE user.username = '".$username."' AND user.password = '".$password."'";
  21.             $result = $link->query($sql);
  22.        
  23.  
  24.             if($result->num_rows > 0){
  25.                 $formatedResult = mysqli_fetch_assoc($result);
  26.                 //$img_encoded = base64_encode ($formatedResult['profile_url']);
  27.                 //$formatedResult['profile_url'] = $img_encoded;
  28.                 echo json_encode($formatedResult);
  29.             }
  30.             else{
  31.                 echo "0";
  32.             }
  33.  
  34.  
  35.             }
  36.            
  37.     else{
  38.         echo "-1";
  39.     }
  40.  
  41.     }
  42.  
  43.  
  44.     if($action == "Reg"){
  45.  
  46.  
  47.         if($username && $password && $email){
  48.  
  49.             $sql = "SELECT * FROM user WHERE user.username = '".$username."' OR user.email = '".$email."'";
  50.             $result = $link->query($sql);
  51.          
  52.  
  53.             if($result->num_rows > 0){
  54.                 echo "-2";
  55.             }else{
  56.                 $insert = "INSERT INTO  user(username, password, email) VALUES ('".$username."','".$password."','".$email."')";
  57.                  
  58.                 $result = $link->query($insert);
  59.  
  60.                 if($result){
  61.                     echo "1";
  62.                 }else{
  63.                     echo "0";
  64.                 }
  65.             }
  66.  
  67.  
  68.         }else{
  69.             echo "-1";
  70.         }
  71.  
  72.  
  73.     }
  74.  
  75. }
  76.  
  77.  
  78.     mysqli_close($link);
  79.  
  80.  
  81.  
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement