2017-03-02 14 views
-1

は私がすべてのセットアップログインページを持っているし、私のリモートデータベースログイン後、通常のユーザー/活性化、ユーザのページにリダイレクト

 id_number username password  UserLevel 
     1   user   user   1 
     2   Activeuser ActiveUser  2 

に接続助けてください、私はそれぞれにユーザーをリダイレクトするためにユーザレベルを使用できるようにしたいですつまり、ユーザーレベル '1'の通常のユーザーはdashboard.phpになり、ユーザーはレベル2のユーザーをDashboardactivated.phpにします。

dreamweaverで既にサーバーの動作を追加しましたが、通常のユーザーはuserlevel '1'でログインしているように見えますが、ユーザーレベル2のアクティブユーザーは同じページにリダイレクトされます。 どうすればいいですか私は私がコードを書くことができないので、私はコード作成の世界に新しいですので、ドリームウィーバーと一緒に働いています。

は、ここに私のコードです:

<?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>&nbsp;</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>&nbsp;</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>&nbsp; 
       </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); 
?> 
+1

あなたのコードは混乱しています。 mysqli prepared statements/pdo prepared statementsを使用してください。クリーンコード –

+1

なぜ誰かがそのような質問をアップヴォートするでしょうか –

+0

いいえ考えてください。彼は0の知識を持っており、私はちょうどうまくいくはずの答えとしていくつかのランダムなコードを入れました。しかし、彼は単純なif文を働かせることさえできません。 –

答えて

0

さてあなたは、IFステートメントを使用して何かを書くことができます。

IF(userlevel == 1) 
{ 
    header:location "dashboard.php" 
} 
ELSE 
{ 
    header:location "dashboardactivated.php" 
} 

のような、これは完全な構文ではありませんので、uが、あなたがこの

以上の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); 
} 
} 

WORKING ADDITION

  $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, [email protected]"; 
     } 
     } 
     } 

上記のこれは私が私のサイトのいずれかに持っていたものです。これは機能します。管理者がログインすると、管理者ページに移動します。ユーザーがログインすると、彼は通常のページに移動します。だからこのようなものを試してみてください。

+1

ここで「if」ステートメントを追加しますか? –

+0

私の答えにいくつかのコードが追加されています。 else文のヘッダ( "location:"。 "flocation.php")に正しい構文を見ることができます。 –

+0

これは私にとってはうまく機能しません。構文エラーが発生しています。どうすればいいの? –

関連する問題