使用odbc进行多重登录

时间:2018-03-12 17:49:15

标签: php html odbc

我需要帮助如何使用数据库表名称中的连接进行多重登录(usercp.php)和(Admincp.php):(级别)。

<?php
session_start();
include('info.php');
$UserID = ms_escape_string($_POST['UserID']);
$Pw = ms_escape_string($_POST['Pw']);
$Error=0;

$res=odbc_exec($conn,"SELECT * FROM PS_UserData.dbo.Users_Master U
INNER JOIN PS_GameData.dbo.Chars UM ON UM.UserUID=U.UserUID
WHERE um.UserID COLLATE DATABASE_DEFAULT = '{$UserID}' 
AND  u.Pw COLLATE DATABASE_DEFAULT = '{$Pw}'"); 

$row=odbc_num_rows($res);
if ($row == 0) {$Error++;}
if ($Error != 0){die ('You Cannot Login Without Atleast One Character');
}else{
header('Location: usercp.php');
}

?>

我已经测试了这段代码但没有锁定它的错误我使用这段代码

登录时:login.php

<?php
session_start();
include('info.php');
$UserID = ms_escape_string($_POST['UserID']);
$Pw = ms_escape_string($_POST['Pw']);
$Error=0;
$user=0;

$res=odbc_exec($conn,"SELECT * FROM PS_UserData.dbo.Users_Master U
INNER JOIN PS_GameData.dbo.Chars UM ON UM.UserUID=U.UserUID
WHERE um.UserID COLLATE DATABASE_DEFAULT = '{$UserID}' 
AND  u.Pw COLLATE DATABASE_DEFAULT = '{$Pw}'"); 

$row=odbc_num_rows($res);
if ($row == 0) {$Error++;}
if ($Error != 0){die ('Incorrect Username or Password');
}else{
    $row = odbc_fetch_array($res);
    session_regenerate_id();
  $_SESSION['sess_user_id'] = $row['UserID'];
  $_SESSION['sess_password'] = $row['Pw'];
        $_SESSION['sess_userrole'] = $row['status'];

        echo $_SESSION['sess_userrole'];
  session_write_close();

  if( $_SESSION['sess_userrole'] == "16"){
   header('Location: admincp.php');
  }else{
   header('Location: usercp.php');
  }

 }


?>

这是我的Usercp.php

<?php 
    session_start();
    $role = $_SESSION['sess_userrole'];
    if(!isset($_SESSION['sess_username']) || $role!="0"){
      header('Location: index.php?err=2');
    }
?>

这是我的Admincp.php

<?php 
    session_start();
    $role = $_SESSION['sess_userrole'];
    if(!isset($_SESSION['sess_username']) || $role!="16"){
      header('Location: index.php?err=2');
    }
?>

所有这个错误,请你帮助我

0 个答案:

没有答案