使用Corona SDK存储用户会话
2020-9-20 17:13:29
收藏:0
阅读:263
评论:0
我正在尝试使用Lua(Corona SDK)构建一个社交应用程序。我想做的是在用户登录/注册时保存用户会话,这样当他们关闭应用程序并再次打开它时不需要登录。
我有点困惑,因为我并不真的了解Lua,但我的代码不起作用。我使用PHP和MySQL作为后端和数据库,我已经在PHP中保存了用户的会话,但如何将会话ID显示到前端并验证它,以便我可以自动登录?
local function networkListener( event )
if ( event.isError ) then
local alert = native.showAlert("Error Logging In", "Check your internet connection .", {"Try again" })
else if event.response == "success" then
-- put the code here to go to where the user needs to be -- after a successful registration
--username = userID
composer.setVariable( "username", username.text )
composer.gotoScene( "feed", { params = parametersToSend } )
composer.removeScene( "login" )
else -- put code here to notify the user of the problem, perhaps -- a native.alert() dialog that shows
--them the value of event.response -- and take them back to the registration screen to let them try
--again
local json = require("json") print( json.prettify( event ) )
local alert = native.showAlert( "Error Logging In", event.response , { "Try again" } )
end
end
end
local function userLogin(event)
if ( "ended" == event.phase ) then
if emptyFields() == true then
else
local parameters = {}
parameters.body = "Login=1&username=" .. username.text .. "&pw=" .. pw.text
local URL = "http://192.168.1.37/hashmobile/process2.php"
network.request(URL, "POST", networkListener, parameters)
local headers = {}
headers["Content-Type"] = "application/x-www-form-urlencoded"
headers["Accept-Language"] = "en-US"
parameters.headers = headers
end
end
end
process2.php:
$sql = "SELECT pw FROM users WHERE username = ?";
$stmt = mysqli_prepare($con, $sql);
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->bind_result($hashed_pwd); //将变量绑定到准备好的语句,用于结果存储
$stmt->fetch(); //从准备好的语句中获取结果并将其存储到绑定的变量中
if (password_verify($pw, $hashed_pwd)) {
//session_id($_POST['user_session_id']); //使用给定的会话ID启动会话
// password verified
$_SESSION["user_session_id"] = $username;
echo "success";
//echo $_SESSION["user_session_id"];
//header('Location: profile.php');
//die();
} else {
//echo 'Incorrect username or Password.';
die('Incorrect username or Password.');
}
这就是我登录到应用程序的方式。有帮助吗?
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
