【发布时间】:2014-04-15 09:18:03
【问题描述】:
我正在学习如何使用 nodejs,并且我正在使用我的 php 经验开发一个聊天页面,我知道 nodejs 对 php 所做的几乎没有任何作用,所以我正在构建整个结构,比如重建 php引擎但只是在节点中,现在我的会话有问题,因为我想创建一个用户系统,所以我进行登录,我很难弄清楚要执行什么过程才能进行登录过程以及是否用户存在,进行会话,我的索引中有这段代码
<!doctype html>
<html>
<head>
<title>Login - Chat</title>
<meta charset="UTF-8">
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
</head>
<body>
<div class="container" id="page">
<h2>Chat Login</h2>
<div id="login-form" class="well">
<form method="post" accept-charset="UTF-8">
<div class="form-group" method="post">
<label for="Username">Username</label>
<input type="text" class="form-control" id="Username" name="Username" placeholder="Enter email">
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="password" class="form-control" id="Password" name="Password" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
<script type="text/javascript">
window.onload = init;
var socketio = io.connect(window.location.hostname);
function init()
{
var login = document.getElementById('login-form');
login.onsubmit = requestData;
}
function requestData()
{
username = document.getElementById('Username');
password = document.getElementById('Password');
//alert if form is empty.
if((username.value && password.value) == '')
{
alert('Box has empty value.');
return false;
}
else
{
socketio.emit('Login_user', {user: username.value, pass: password.value});
}
}
</script>
</body>
</html>
我使用 socket.io 将数据从客户端传输到服务器,反之亦然(我仍在学习它的套接字)。我在这一步被卡住了,我只需要知道如何在 nodejs 中处理会话,我有我的 github 存储库:Chat 所以你可以在那里看到我的整个代码,知道如何处理会话吗? .
PD:我只是一个新手开发人员,我使用 PHP 大约 6 个月,使用 node 大约 2 周,我不想使用任何框架来更好地学习语言。
【问题讨论】: