0

i've my check_phone.php page on server as this:

  <?php
session_start(); ob_start();

require '../platform2/pages/config.php';
require '../platform2/pages/function.php';

date_default_timezone_set('Europe/London');
if(isset($_POST['login']))
{
$email=mysql_real_escape_string(htmlspecialchars(trim($_POST['email'])));
$password=mysql_real_escape_string(htmlspecialchars(trim($_POST['password'])));
$stro = "select * from user where email='$email' and pwd='$password' ";
$res = mysql_query($stro) or die(mysql_error());
$login=mysql_num_rows($res);

if($login!=0)
{
echo "success";
} else {
echo "failed";
}
}

?>

And i call it from Jquery ajax call in my phonegap application in this way:

    <script>
    $("#login").click(function(){

    var email=$("#email").val();
    var password=$("#password").val();
    var dataString="email="+email+"&password="+password+"&login=j";
    var url = "../sandbox/platform/check_phone.php";


    if($.trim(email).length>0 & $.trim(password).length>0)
    {
    $.ajax({
    type: "POST",
    url: url,
    data: dataString,
    crossDomain: true,
    cache: false,
    beforeSend: function(){ $("#login").html('Connecting...');},
    success: function(data){
    data = $.trim(data);
    if(data=="success")
    {
    localStorage.login="true";
    localStorage.email=email;
    window.location.href = "wow.html";
/* in a normal php-application i used to store, $_SESSION['user'] $_SESSION['login'] , but i don't know how to do it in phonegap */

    }
    else if(data="failed")
  {
    alert("Login error");
    alert(data);
    $("#login").html('Login');
  } 

 }
                                                                                    });
        }      return false;





    });
    </script>

Now, my question is: how i can save session of a User and continue to use his Session on a further request as retriving profile,make new post etc.. I've already thought to use SetLocalStorage as Username and Password, and call it with my request in every call. But i don't know if it make west time for my server than give me a slowly response. Is there a way for keeping session as i do on a normal request on my server?

Thanks

  • 1
    First of all, [don't use `mysql_*`](https://stackoverflow.com/questions/6980792/what-is-pdo-why-should-i-use-it). Use PDO or at least `mysqli_*`. Secondly, format your code to be readable. Thirdly, take a look at [this question](https://stackoverflow.com/questions/10097887/using-sessions-session-variables-in-a-php-login-script). – lolbas Feb 19 '18 at 08:31
  • 1
    Possible duplicate of [Using sessions & session variables in a PHP Login Script](https://stackoverflow.com/questions/10097887/using-sessions-session-variables-in-a-php-login-script) – lolbas Feb 19 '18 at 08:31
  • @lolbas thank u for mysqli_* i will use it, but is not about that my question. As you can read i'm talking about saving session in a phonegap hybrid app, not in a normal php login page. – Gianluca Giordano Feb 19 '18 at 08:36
  • 1
    For phonegap application use [localStorage](https://www.w3schools.com/html/html5_webstorage.asp) – proofzy Feb 19 '18 at 08:40

0 Answers0