I have a simple login system in ionic that is operating normally. The system checks whether the user exists in the mysql database. If the user is there, it returns 1. If not, it returns 0. This return value is sent via json.
My problem is that I need to send user data to the next screen and in that data insert some extra information in the user registration. For example, after logging in the application takes the latitude and longitude of the user. I want to keep this latitude and longitude on their registration.
This is the login.php:
<?php
session_start();
header("Access-Control-Allow-Origin: *");
$mysql_host = "localhost:3306";
$mysql_database = "melleve";
$mysql_user = "root";
$mysql_password = "";
// Create connection
$conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$email = $_POST['email'];
$senha = $_POST['senha'];
$sql = "SELECT * FROM cadast WHERE email='$email' AND senha='$senha'";
$result = $conn->query($sql);
$res=mysqli_fetch_array($result);
$rs = mysqli_num_rows($result);
if($rs>0)
{
if(!isset($_SESSION))
session_start();
$_SESSION['id']=$res['id'];
$_SESSION['nome']=$res['nome'];
$_SESSION['email']=$res['email'];
$login = 1;
}
else
{
$login = 0;
}
echo (json_encode($login));
?>
This is the login controller:
.controller('lg', function($scope, $state) {
$scope.logar = function(){
var formula = $('#formLogin').serialize();
$.ajax({
type : 'POST',
data : formula,
url : 'http://localhost/melleve/login.php',
success : function(data){
if(data == '' || data == 0){
alert('Login ou senha inválidos');
}
if(data == 1){
alert('Login realizado com sucesso');
//$state.go('app.atigmaps');
}
}
})
}
})