分发器注册和退出登录
程序员文章站
2022-02-11 06:30:54
...
完善注册页面,复制登录页面,增加密码确认和性别
连接数据库,添加数据
function insertData($name, $pwd, $gender, $created_at)
{
global $pdo;
$sql = "INSERT INTO `user` SET `username`=?,`password`=?,`gender`=?,`created_at`=?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $pwd, $gender, $created_at]);
if ($stmt->rowCount() == 1) {
$flag = true;
}
return $flag;
}
增加后端可接受的参数gender,created_at
请求分发器 注册,退出登录
switch ($type) {
case 'reg':
$res = insertData($name, $pwd, $gender, $created_at);
if ($res) {
echo json_encode(['status' => 1, 'msg' => '注册成功'], 320);
exit;
}
echo json_encode(['status' => 0, 'msg' => '注册失败'], 320);
break;
case 'logout':
//删除注册的session数据文件 关闭session会话
session_destroy();
header('Location:index.php');
break;
default:
exit('非法请求');
}
上一篇: 用php进行socket通讯
下一篇: PHP如何操作JSON数据