2

注意:首先我使用 PHP、HTML、CSS、MySQL(数据库),还使用 ​​Dreamweaver 6 来编辑我的所有代码。

好的,所以对于我最后一年的项目,我正在创建一个电子考勤跟踪和监控系统。我在为多个用户创建登录名时遇到了很大的困难。该系统的三个用户是 STAFF、PARENTS 和 STUDENTS。为此,我专注于 STAFF

好的,所以我有...

  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");

    }

}

index.php 的 PHP 脚本是

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

我将 staff_home.php 放在索引中,因为当我不断被重定向到 index.php 时,我将代码放在顶部,希望它只是将我重定向到 Staff_home.php

staff_home.php 的 PHP 脚本是

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

我怀疑也许我必须分配用户角色,但我没有这样做。

所以我想要的是员工登录并重定向到staff_home.php,学生登录并重定向到student_home,父母登录并重定向到parent_home。

几个月来我一直在尝试练习 PHP,但最小的错误真的让我很烦恼,哈哈。我祈祷有人能帮助我!这可能看起来像一个小错误,但我会永远感激任何关于如何改进我的代码并让它发挥作用的提示和建议。我会回来看看是否有人回复,我的电子邮件是 jmudhar90@hotmail.co.uk。

问候人们

4

1 回答 1

0

I don't see session_start() in your code at any point. You need to call session_start() before you can use sessions in a page.

于 2013-02-21T21:48:02.383 回答