我现在正在构建一个移动版网站,就像www.example.com/m/
一样。现在我遇到了一个问题,即我无法使用移动设备(Android,iPhone,iPad)登录网站。
但是,它适用于以下情况:
localhost
localhost
server
这意味着当我使用移动设备登录服务器时它才起作用。
$dbCon = dbConnect::create();
$login = $_POST['login'];
$password = $_POST['password'];
//================= Loading Member Informations====================================
$sql = "select * from members where (phone = '$login' or email = '$login') and password = '$password' limit 1";
if ($result = mysqli_query($dbCon,$sql)) {
$rows_num = 0; //record?
while($row = mysqli_fetch_array($result)) {
$rows_num++;
//================== Get Member data ===================================================
$user_id = $row['id'];
$display_name = (empty($row['display_name']))? $row['name'] : $row['display_name'];
$email = $row['email'];
$phone = $row['phone'];
$email_confirm = $row['email_confirm'];
$member_type = $row['member_type'];
if($email==$login){ $loginby = 'email'; }elseif($phone==$login){ $loginby = 'phone'; }
//==================================================================================
//================ Remember me ================================
if($_POST['remanber_me']=="on"){
setcookie("user_id",$user_id,time()+60*60*24*30);
setcookie("display_name",$display_name,time()+60*60*24*30);
setcookie("email",$email,time()+60*60*24*30);
setcookie("phone",$phone,time()+60*60*24*30);
setcookie("email_confirm",$email_confirm,time()+60*60*24*30);
setcookie("loginby",$loginby,time()+60*60*24*30);
setcookie("member_type",$member_type,time()+60*60*24*30);
}
//================================================================
//================= SESSION==========
$_SESSION['user_id'] = $user_id;
$_SESSION['display_name'] = $display_name;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
$_SESSION['email_confirm'] = $email_confirm;
$_SESSION['loginby'] = $loginby;
$_SESSION['member_type'] = $member_type;
//===========================================
//======================== Update last login time ===============================
$sql = "update members set last_login_time = NOW(), last_login_ip = '$ip' where id = $user_id";
$dbCon->query($sql);
//======================================================================
}
在abover脚本上,它可以更新用户上次登录信息。所以目前我猜这个问题出现在sessions
上。但是,我不知道如何真正解决问题...
编辑:当我在while循环中执行print_r($_SESSION)
和print_r($row)
时,它有记录。但是当脚本重定向回index.php
或其他页面时,它仍然没有登录网站。
此外,当我首先登录www.example.com
然后返回www.example.com/m/
时,它仍然可以保留我的登录状态...我无法直接通过www.example.com/m/
登录。
答案 0 :(得分:0)
好吧......我刚发现我错过了另一个$_SESSION
变量..通常它应该是:
$_SESSION['user_id'] = $user_id;
$_SESSION['display_name'] = $display_name;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
$_SESSION['email_confirm'] = $email_confirm;
$_SESSION['loginby'] = $loginby;
$_SESSION['member_type'] = $member_type;
$_SESSION['action_time'] = time(); //the stuff i missed
因此,用户登录系统后会自动退出...
这真是一个不小心的错误......我应该提醒自己不要再这样做了......