gpt4 book ai didi

mysql - 为不同成员类型 AJAX 创建 session

转载 作者:行者123 更新时间:2023-11-30 00:58:38 25 4
gpt4 key购买 nike

我已经成功创建了一个 AJAX 登录系统,但是我想实现它来查看实例成员和 super 成员的两个表。我想根据用户名的第一个字符重定向用户。有人知道我该怎么做吗?

<?php
ob_start();
include_once 'config.php';
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and print "true"
echo "true";
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;

}
else {
//return the error message
echo "<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>Wrong Username or Password</div>";
}
ob_end_flush();

?>

这就是我在主登录页面启动 session 的方式

<?php
session_start();
if (isset($_SESSION["myusername"])) {
header("location:login_success.php");
}
?>

最佳答案

在用户表中添加“memberType”列,然后设置 $_SESSION['myMemberType'] = $mymembertype,最后与“if”语句进行比较并重定向!像这样的事情:

<?php
session_start();
if (isset($_SESSION["myusername"]) && isset($_SESSION["myMemberType"])) {
if($_SESSION["myMemberType"] == "members") {
header("location:login_success_member.php");
}
if($_SESSION["myMemberType"] == "super members") {
header("location:login_success_supermember.php");
}
}
?>

关于mysql - 为不同成员类型 AJAX 创建 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20336258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com