2013-02-21 97 views
2

注意:首先我使用PHP,HTML,CSS,MySQL的(數據庫),也使用Dreamweaver 6編輯我的所有代碼用戶登錄到index.php

好,所以我最後我正在創建一個電子考勤跟蹤和監控系統。我爲創建多個用戶登錄遇到很大困難。這個系統的三個用戶是STAFF,PARENTS &學生。對於這一點,我注重對員工的

行,所以我有...

  1. staff_register.php
  2. staff_verify.php
  3. staff_login.php
  4. staff_home.php

因此,當一個員工要簽署他們必須先註冊。所以我有一個表單,當提交完全寫入數據庫。 student_register.php職位,以student_verify.php,其中在該激活電子郵件被髮送到用戶,要求他們驗證自己(點擊鏈接)。一旦用戶驗證,他們就成爲活躍用戶。然後他們進入登錄頁面。當用戶輸入他們的詳細資料,我重定向回index.php文件在哪裏我的代碼具體說明,以重定向到staff_home.php下面我將提供一些代碼:

這是staff_login.php:

   <?php include_once("scripts/global.php"); 
       $message = ''; 
       ` `if(isset($_POST['email'])){ 
      $email = $_POST['email']; 
    $pass = $_POST['pass']; 
    $remember = $_POST['remember']; ` 

//error handeling 
if((!$email) || (!$pass)){ 
    $message = 'please insert both fields'; 
}else{ 
    //secure the data 
    $email = mysql_real_escape_string($email); 
    $pass = sha1($pass); 
    $query = mysql_query("SELECT * FROM staff WHERE email='$email' 
      AND password='$pass' LIMIT 1") or die("Could not check member");  
    $count_query = mysql_num_rows($query); 
    if($count_query == 0){ 
     $message = 'The infomation you entered was incorrect'; 
    }else{ 
     //start the sessions 
     $_SESSION['pass'] = $pass; 
     while($row = mysql_fetch_array($query)){ 
      $username = $row['username']; 
      $id = $row['id']; 
     } 
     $_SESSION['username'] = $username; 
     $_SESSION['id'] = $id; 

     if($remember == "yes"){ 
      //create the cookies 
      setcookie("id_cookie", $id, time()+60*60*24*100, "/"); 
      setcookie("pass_cookie", $pass, time()+60*60*24*100, "/"); 
     } 

     header("Location: staff_home.php"); 

    } 

} 

PHP腳本的index.php文件是

<?php include_once("scripts/global.php"); 
    if ($logged == 1) { 
     header("Location: staff_home.php"); 
     exit; 
    } 
?> 

我把staff_home.php索引因爲我一直得到重定向到index.php我希望把代碼的頂部,它只是重定向我staff_home.php

PHP腳本的staff_home.php是

<?php include_once("scripts/global.php"); 
    if ($logged == 0) { 
     header("Location:staff_home.php"); 
     exit(); 
    } 
?> 

我懷疑,也許我必須分配用戶的角色,這是我沒有做過。

所以我想要的是員工登錄並重定向到staff_home.php,學生登錄並重定向到student_home和父母登錄並重定向到parent_home。

我一直在努力練習PHP幾個月,但點點的錯誤真的來煩我笑。我祈禱有人能幫助我!這似乎是一個小錯誤(S),但我將是關於如何提高我的代碼,並把它發揮作用的任何提示和建議foreever感激。我會查看是否有人回覆,並且我的電子郵件是[email protected]

問候人民

+0

你有staff_home.php重定向到index.php代碼,如果用戶試圖訪問該頁面,但沒有登錄? – 2013-02-21 21:28:14

+0

我不明白這個問題。您是否有員工,家長和學生的多餘登錄頁面?如果是這樣,只需將每個登錄頁面直接指向正確的主頁,就像您爲員工登錄頁面所做的那樣。 – 2013-02-21 21:29:27

+0

您如何知道數據庫中的人員是學生,工作人員還是家長? – 2013-02-21 21:32:12

回答

0

我沒有看到session_start()在你的代碼的任何一點。您需要先致電session_start(),然後才能在頁面中使用會話。

+0

好吧我把session_start();在staff_home,並已改變staff_home.php重定向到index.php仍然重定向到index.php – 2013-02-21 22:00:08