<?php
function enableCORS() {
 
    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    //    header('Access-Control-Allow-Credentials: true');
    //    header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }
 
    // Access-Control headers are received during OPTIONS requests
 /*   if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
 
        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
 
        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
 
        exit(0);
    }
 */
    return true;
}

enableCORS();

include("configuracao.php");//confirma no banco de dados
 
$usuario = $_GET['usuario'];
$senha = $_GET['senha']; 

//$SQL = "SELECT * FROM clientes WHERE login='$usuario' AND senha='$senha' AND status <> 'Bloqueado' LIMIT 0,1";

$SQL = "SELECT * FROM usuarios WHERE usuario='$usuario' AND senha='$senha' LIMIT 0,1";

$table = mysql_query($SQL, $conexao) or die(mysql_error());
 
while ($row = mysql_fetch_array($table))  
{
    
    $i=0;                 
    foreach($row as $key => $value)    
    {
    
        if (is_string($key)) 
        {
         $fields[mysql_field_name($table,$i++)] = $value;
        }
 
    
    }
 
    $json_result["usuarios"] [ ] =  $fields;
    
}


$JSON = json_encode($json_result);

print_r($JSON);

 ?> 
