2015-06-21 32 views
0

我想开发一个登录系统在PHP中有faculty_login.php其中displays faculty_login_option.inc.php它有一个登录表单,如果$_SESSION['f_id']设置它重定向到faculty_upload_option.php。其中教师细节牵强使用$f_id = $_SESSION['f_id']为主要key.but $_SESSION['f_id']faculty_table总是返回1和用户作为其f_id用户登录是1

<?php 

//faculty login page.faculty_login.php 
//if logged in show upload option/show login option. 

require_once 'resources/core.inc.php';//session is set here 
require_once 'resources/connect.inc.php';//init db connection 

    if(isset($_SESSION['f_id'])&&!empty($_SESSION['f_id'])){ 
require_once 'faculty_upload_option.inc.php'; 
    } 
    else{ 
    require_once 'faculty_login_option.inc.php'; 
    } 

?> 

<?php 

/* faculty_login_db.php 
    * Check if the faculty can login or the credentials are wrong. 
    */ 

    require_once 'resources/core.inc.php'; 
    require_once 'resources/connect.inc.php'; 


    if(isset($_POST['f_username'])&&isset($_POST['f_password'])){ 
    if(!empty($_POST['f_username'])&&!empty($_POST['f_password'])){ 
       $username = stripcslashes($_POST['f_username']); 
       $password = stripcslashes($_POST['f_password']); 
       $result = $conn->prepare("SELECT f_id FROM faculty_table  WHERE f_username= :hjhjhjh AND f_password= :asas"); 
       $result->bindParam(':hjhjhjh', $username); 
       $result->bindParam(':asas', $password); 
       $result->execute(); 
       $rows = $result->fetch(PDO::FETCH_NUM); 
       if($result->rowCount() == 1) { 
        $_SESSION['f_id'] = $rows ; 
        $_SESSION['f_username'] = $username; 
        header('Location:faculty_login.php'); 
       } 
       else{ 
        header('Location:faculty_login.php?username='.$username); 
       } 
      } 
      else{ 
       header('Location:faculty_login.php'); 
      } 
     } 
     else{ 

       header('Location:faculty_login.php'); 
     } 


    ?> 

     <?php 

     /* faculty_login_option.php 
     * faculty login page. check if user exists/ use faculty_login_db.php 
     */ 

      ?> 



     <!DOCTYPE html> 
     <!-- 
     To change this license header, choose License Headers in Project Properties. 
      To change this template file, choose Tools | Templates 
      and open the template in the editor. 
       --> 
       <html> 
      <head> 
    <title>Home</title> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1"> 
    <link rel="stylesheet" href="resources/loginstyle.css"> 
</head> 
<body> 
    <?php 
    //<img alt="full screen background image" src="images/orange.jpg" id="full-screen-background-image" /> 
    ?> 
    <a href="mobileindex.html"><div id="back">Home</div></a> 
    <div id="header"> 
     <h3>FACULTY LOGIN</h3><br> 
    </div> 
    <hr> 



    <div id="container"> 
     <center> 
      <form action="faculty_login_db.php" method="post"> 
       <input type="text" onFocus="if(this.value=='Username'){this.value=''}" name="f_username" class="buttons" value="<?php 
        if(isset($_GET['username'])) 
         { 
         echo $_GET['username']; 
         }else{echo 'Username';} 
        ?>"><br> 
       <input type="password" onFocus="if(this.value=='Password'){this.value='';}" name="f_password" class="buttons" value="Password"><br> 
       <input type="submit" value="Login" class="lbutton"> 
      </form> 
     </center> 

    <?php 
     if(isset($_GET['username'])){ 
      ?> 
     <div id="errormsg">Username or password is invalid.</div> 
     <?php 
     } 
    ?> 

</body> 

<?php 

    /* this is faculty_upload_option.inc.php 
    * To change this license header, choose License Headers in Project  Properties. 
     * To change this template file, choose Tools | Templates 
     * and open the template in the editor. 
     */ 
     require_once 'resources/core.inc.php'; 
     require_once 'resources/connect.inc.php'; 

if(isset($_SESSION['f_id'])&&isset($_SESSION['f_username'])&&!empty($_SESSION['f_id'])){ 
    $f_id=trim(isset($_SESSION['f_id'])); 
     if(!empty($f_id)){ 
    $result = $conn->prepare("SELECT * FROM faculty_table WHERE f_id=:id"); 
    $result->bindparam(':id', $f_id); 
    $result->execute(); 
    $rows = $result->fetchAll(); 
    foreach($rows as $db_rows){ 
    $f_username = $db_rows['f_username']; 
    $category = $db_rows['category']; 
    $branch = $db_rows['branch']; 
    } 
    //page which should be displayed if user logs in.?> 


    <html> 
    <head><title><?php echo $f_username; ?></title> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1"> 
    <link href='http://fonts.googleapis.com/css?family=Indie+Flower|Yanone+Kaffeesatz' rel='stylesheet' type='text/css'> 
     <link rel="stylesheet" href="resources/upload_style.css">  
    </head> 
    <body><div id="parent"> 
    <div id="header"> 
     <img src="images/no-profile-image.png" width="30%" id="noimg"> 
     <span id="addfont"><h1><?php echo $f_username;?></h1></span> 
     <h2><?php echo $category;?></h2> 
    <p><?php echo $branch;?></p> 
     <center><a href="mobileindex.html"><div class="buttons" id="left">Home</div></a><a href="logout.php"><div class="buttons" id="right">Logout</div></a></center> 
    </div> 
+1

你应该发布你的代码,看看发生了什么。 –

+0

哦,对不起,我有4个文件。我病了编辑。感谢您的耐心。 –

回答

0

您是否正确地摧毁会议登出?你是否在遇到某种情况之前设置了会话ID?达到比较条件之前的值是多少?

+0

Iam using if(isset($ _ SESSION ['f_id'])){session_destroy();} –

+0

'$ _SESSION ['f_id'] = $ rows ['f_id'];' – Kabir

+0

Ya正在使用f_id设置会话它的用户名和密码组合是有效的。 –