我已成功创建了一个AJAX登录系统,但是我想实现它以查看实例成员和超级成员的两个表。我想根据用户名的第一个字符重定向用户。有谁知道我怎么能这样做?
<?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\">×</button>Wrong Username or Password</div>";
}
ob_end_flush();
&GT;
这就是我在主登录页面中启动会话的方式
<?php
session_start();
if (isset($_SESSION["myusername"])) {
header("location:login_success.php");
}
?>
答案 0 :(得分:0)
您可以创建一个名为UserTypes的表,其中包含id和privilege,然后向用户添加一个类似user_type_id的列,用于跟踪用户的权限级别。然后基于user_type _id,您可以将人们重定向到正确的页面。谷歌外键获取更多信息
答案 1 :(得分:0)
在users表中添加一列“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");
}
}
?>