如何在PHP ajax phonegap APP上保持会话

时间:2018-02-19 08:26:17

标签: php session web-applications phonegap hybrid

我在服务器上的check_phone.php页面是这样的:

  <?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";
}
}

?>

我以这种方式在我的phonegap应用程序中通过Jquery ajax调用来调用它:

    <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>

现在,我的问题是:如何保存用户的会话并继续使用他的会话进一步请求作为重新审阅个人资料,制作新帖子等。 我已经考虑过使用SetLocalStorage作为用户名和密码,并在每次通话时使用我的请求来调用它。 但我不知道它是否为我的服务器提供西部时间而不是给我一个缓慢的响应。 有没有办法像我在服务器上的正常请求那样保持会话?

由于

0 个答案:

没有答案
相关问题