请帮助我设置登录页面并连接到我的远程数据库
id_number username password UserLevel
1 user user 1
2 Activeuser ActiveUser 2
,我希望能够使用UserLevel将用户重定向到他们各自的页面,即普通用户使用userlevel' 1'使用userlevel' 2'激活用户时使用dashboard.php到Dashboardactivated.php。
已经在Dreamweaver中添加了服务器行为,但它似乎只能通过userlevel登录普通用户' 1'而激活用户使用userlevel' 2'被重定向到同一页面。 请问我该怎么做才能忍受我对编码世界不熟悉所以我正在使用Dreamweaver,因为我不能自己编写代码。
这是我的代码:
<?php require_once('Connections/CashSpray.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_Login = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Login = $_SESSION['MM_Username'];
}
mysql_select_db($database_CashSpray, $CashSpray);
$query_Login = sprintf("SELECT * FROM users WHERE Username = %s", GetSQLValueString($colname_Login, "text"));
$Login = mysql_query($query_Login, $CashSpray) or die(mysql_error());
$row_Login = mysql_fetch_assoc($Login);
$totalRows_Login = mysql_num_rows($Login);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['UserName'])) {
$loginUsername=$_POST['UserName'];
$password=$_POST['Password'];
$MM_fldUserAuthorization = "UserLevel";
$MM_redirectLoginSuccess = "dashboard.php";
$MM_redirectLoginFailed = "log-in.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_CashSpray, $CashSpray);
$LoginRS__query=sprintf("SELECT Username, Password, UserLevel FROM users WHERE Username=%s AND Password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $CashSpray) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'UserLevel');
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60745 -->
<meta charset="utf-8">
<title>Log In!</title>
<meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="style.css" media="screen">
<!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
<link rel="stylesheet" href="style.responsive.css" media="all">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="script.responsive.js"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
<style>
.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px; }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
</style>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="art-main">
<header class="art-header">
<div class="art-shapes">
<div class="art-object111552341"></div>
<div class="art-object1196905085"></div>
</div>
</header>
<nav class="art-nav">
<div class="art-nav-inner">
<ul class="art-hmenu"><li><a href="home.php" class="">Home</a></li><li><a href="how-it-works.php" class="">How It Works</a></li><li><a href="sign-up.php" class="">Sign Up</a></li><li><a href="log-in.php" class="active">Log In</a></li><li><a href="contact-us.php">Contact Us</a></li></ul>
</div>
</nav>
<div class="art-sheet clearfix">
<div class="art-pageslider">
<div class="art-shapes">
</div>
<div class="art-slider art-slidecontainerpageslider" data-width="880" data-height="250">
<div class="art-slider-inner">
<div class="art-slide-item art-slidepageslider0">
</div>
<div class="art-slide-item art-slidepageslider1">
</div>
<div class="art-slide-item art-slidepageslider2">
</div>
<div class="art-slide-item art-slidepageslider3">
</div>
</div>
</div>
<div class="art-slidenavigator art-slidenavigatorpageslider" data-left="1" data-top="0">
<a href="#" class="art-slidenavigatoritem"></a><a href="#" class="art-slidenavigatoritem"></a><a href="#" class="art-slidenavigatoritem"></a><a href="#" class="art-slidenavigatoritem"></a>
</div>
</div>
<div class="art-layout-wrapper">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content"><article class="art-post art-article">
<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%" >
<h2><img width="76" height="81" alt="" class="art-lightbox" src="images/user-login-icon-29.png"><span style="font-weight: bold;"><span style="font-family: Georgia; color: #065179;">Log In!</span></span></h2><h2><span style="font-weight: bold;"><span style="font-family: Georgia; font-size: 20px;">Please Enter Your Correct Details!..</span></span></h2><h2><span style="font-weight: bold;"><br></span></h2>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="LoginForm" id="LoginForm">
<table width="500" border="0">
<tr>
<td> </td>
</tr>
<tr>
<td><span id="sprytextfield1">
<label for="UserName"></label>
UserName <br>
<input type="text" name="UserName" id="UserName">
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><span id="sprypassword1">
<label for="Password"></label>
Password <br>
<input type="password" name="Password" id="Password">
<span class="passwordRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td><p>
</p>
<p>
<input name="LoginButton" type="submit" class="art-button" id="LoginButton" value="Login">
</p></td>
</tr>
<tr>
<td>Dont Have An Account Yet? <a href="sign-up.php"><u>Sign Up.</u></a></td>
</tr>
</table>
</form>
<h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span></h2><h2><span style="font-weight: bold;"><br></span><br></h2>
</div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="art-footer">
<div class="art-footer-inner">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%">
<p><span style="font-size: 16px; color: #FFFFFF;">Copyright © 2017, CASHSPRAY. All Rights Reserved.</span></p>
</div>
</div>
</div>
<p class="art-page-footer">
<span id="art-footnote-links">Designed by <a href="cashspray.com" target="_blank">CashSpray</a>.</span>
</p>
</div>
</footer>
</div>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprypassword1 = new Spry.Widget.ValidationPassword("sprypassword1");
</script>
</body></html>
<?php
mysql_free_result($Login);
?>
答案 0 :(得分:0)
你可以用IF语句写一些东西。 喜欢
IF( userlevel == 1 )
{
header:location "dashboard.php"
}
ELSE
{
header:location "dashboardactivated.php"
}
这不是完整的语法,所以如果你打算使用这个
,你必须纠正这个问题如果有超过2个用户级别。你可以添加一个ELSEIF来获得更多选择。
ADDITION
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
IF( userlevel == 1 )
{
header:location "dashboard.php"
}
ELSE
{
header:location "dashboardactivated.php"
}
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
工作增加
$sql2="SELECT * FROM admins WHERE Username='$Username' and Password='$Password'";
$result2=mysql_query($sql2);
$count2=mysql_num_rows($result2);
$sql1="SELECT * FROM customers WHERE Username='$Username' and Password='$Password'";
$result=mysql_query($sql1);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION['user'] = $Username;
header("Location:index.php");
}
else if($count2==1){
$_SESSION['admin'] = $Username;
header("Location:indexAdmin.php");
}
else{
echo " Nee, Cy@";
}
}
}
以上是我在其中一个网站上的内容。这很有效。如果管理员登录,则会将他带到管理页面。如果用户登录,则会将他带到正常页面。所以试试看起来像这样的东西,