I have a problem with app híbrida
, I have two input fields where I put username and password and that sent it to a URL
in which is the script PHP
hosted (web server that is free) and that request is blocked.
From what I have read it has to do with browser security ( Cors
) What can be done in this case? I've tried it locally, building apk
for android
and nothing, I've added a complement of proxyalgo
and nothing, some help please.
This is part of the code with which I try to make my requests
.controller('loginCtrl', function($scope,$rootScope,$http) {
$scope.logear = function($scope){
$scope.mensaje = $rootScope.mensaje;
//alert($rootScope.mensaje);
var url = "http://185.27.134.110/carpeta/php/login.php";
var emaillog = $scope.emailLog;
var passlog = $scope.passlog;
$http.post(url,{'emaillog':emaillog,'passlog':passlog,'accion':'logear'})
.success(function(data,status,headers,cofing){
console.log(data);
console.log(status);
console.log(headers);
console.log(cofing);
// SI EL ESTADO ES TRUE SE REDIRECIONA AL LA PANTALLA PRICIPAL DE INICIO SESION
if(data.estado== true){
//SE REDIRECIONA AL ACCESO PARA PODER EFEFTUAR LLAMADAS
window.location="http://185.27.134.110/carpeta/#/acceso";
//ASIGNAMOS VALORES A VARIABLES GLOBALES PARA UTILIZARLA EN LA SIGUEINTE VISTA
$rootScope.mensajeinicio = data.contenido;
$rootScope.nombreUser = data.contenido;
}else{
window.location="http://185.27.134.110/carpeta/#/login";
}
//alert(data.existe);
});
}
})
and code PHP
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
include_once 'class.Conexion.php';
$data = json_decode(file_get_contents("php://input"));
$email = ($data->email);
$accion = ($data->accion);
$salidaJson = "";
$contenido = array();
//$contenidoDos = array();
$estado = false;
$existe = "false";
if($accion == 'validarDatos'){
$pass = ($data->pass);
$nombre = ($data->nombre);
$db = new conexion();
$sql = $db->query("SELECT * FROM registro WHERE email ='".$email."' ");
if($db->rows($sql)> 0){
//SI EXISTE EL EMAIL SE DEBE CARGAR ALA PANTALLA DE INICIO DE SESION
//DE LO CONTRARIO SE REGISTRARA
while($rew = $db->recorrer($sql)){
$contenido = array(
'nombre' => $rew['nombre_completo'],
'email' => $rew['email'],
'respuesta' => 'Email Registrado - Inicie Sesion'
);
}
$estado = true;
$existe = true;
}else{
$sql = $db->query("INSERT INTO registro(nombre_completo,email,pass)VALUES('".$nombre."','".$email."','".$pass."')");
if(!mysql_error()){
$contenido = array("respuesta" => 'REGISTRO REALIZADO CON EXITO');
$estado = true;
$existe = true;
}else{
$contenido = array(
"respuesta" => 'ERROR AL INTENTENTAR REGISTRARSE, PORFAVOR INTENTELO NUEVAMENTE!!');
$estado = false;
$existe = false;
}
//$estado = false;
}
}elseif($accion == 'getDatos'){
$db = new conexion();
$sql = $db->query("SELECT * FROM registro WHERE email ='".$email."' ");
if($db->rows($sql)> 0){
//SI EXISTE EL EMAIL SE DEBE CARGAR ALA PANTALLA DE INICIO DE SESION
//DE LO CONTRARIO SE REGISTRARA
while($rew = $db->recorrer($sql)){
$contenido = array(
'nombre' => $rew['nombre_completo'],
'email' => $rew['email']
);
}
$estado = true;
}
}elseif($accion == 'getLineas'){
$db = new conexion();
$sql = $db->query("SELECT * FROM lineas");
if($db->rows($sql)> 0){
//SI EXISTE EL EMAIL SE DEBE CARGAR ALA PANTALLA DE INICIO DE SESION
//DE LO CONTRARIO SE REGISTRARA
while($rew = $db->recorrer($sql)){
$contenido = array(
'nombreLinea' => $rew['nombre_linea'],
'numeroLinea' => $rew['numero_linea']
);
}
$estado = true;
}else{
$estado = false;
}
}
$salidaJson = array("contenido" => $contenido,
"estado" => $estado,
"existe" => $existe);
//header('Context-type: application/json');
echo json_encode($salidaJson);
// mysqli_close($sql);
?>
Error:
CORS Crossover blocked request: The same origin policy does not allow the reading of remote resources in 185.27.134.110/folder/php/consultas.php. (Reason: CORS header 'Access-Control-Allow-Origin' not present)