如何在php中使用不同的用户类型登录?

时间:2016-10-26 05:23:08

标签: php mysql session

  <?php
    session_start();
    include("includes/connection.php");
    if($_REQUEST['submit']=='submit1')
    {
        $R=$_REQUEST;
        $sql=mysql_query("select * from `registration` where `reg_email`='$R[reg_email]'");
        if(mysql_affected_rows()>0)
        {
            echo "<script>alert('Try with another Email....')</script>";
        }
        else
        {
            if($_REQUEST['reg_type']=='corporate')
            {
                $sql="INSERT INTO `registration` (`reg_name`, `reg_email`, `reg_pass`, `reg_age`, `reg_education`, `reg_gender`, `reg_designation`, `reg_place`, `reg_mobile`, `reg_type`, `reg_orgname`) VALUES ('$R[reg_name]', '$R[reg_email]', '$R[reg_pass]', '$R[reg_age]', '$R[reg_education]', '$R[reg_gender]', '$R[reg_designation]', '$R[reg_place]', '$R[reg_mobile]', '$R[reg_type]', '$R[reg_orgname]')";
                //echo $sql;
                mysql_query($sql);
                if(mysql_affected_rows()>0)
                {
                    $_SESSION['email']=$R['reg_email'];
                    $_SESSION['org_name']=$R['reg_orgname'];
                    header("location:organization_home.php");
                }
            }
            else
            {
                $sql="INSERT INTO `registration` (`reg_name`, `reg_email`, `reg_pass`, `reg_age`, `reg_education`, `reg_gender`, `reg_designation`, `reg_place`, `reg_mobile`, `reg_type`) VALUES ('$R[reg_name]', '$R[reg_email]', '$R[reg_pass]', '$R[reg_age]', '$R[reg_education]', '$R[reg_gender]', '$R[reg_designation]', '$R[reg_place]', '$R[reg_mobile]', '$R[reg_type]')";
                //echo $sql;
                mysql_query($sql);
                if(mysql_affected_rows()>0)
                {
                    $_SESSION['email']=$R['reg_email'];
                    header("location:individual_home.php");
                }
            }
        }
    }


    #### checklogin details ##
    #------------------------------#
    if($_REQUEST['submit']=='login')
    {
        $R=$_REQUEST;
        $sql=mysql_query("select * from `registration` where `reg_email`='$R[reg_email]'");
        if(mysql_affected_rows()>0)
        {
            $data=mysql_fetch_assoc($sql);
            if($data['reg_pass']==$R['reg_password'])
            {
                if($data['reg_orgname']!=="")
                {
                    $_SESSION['email']=$R['reg_email'];
                    $_SESSION['org_name']=$data['reg_orgname'];
                    header("location:organization_home.php");
                }
                else
                {
                    $_SESSION['email']=$R['reg_email'];
                    header("location:individual_home.php");
                }
            }
            else
            {
                echo "<script>alert(' Email or password incorrect....')</script>";
            }
        }
        else
        {
            echo "<script>alert(' Email or password incorrect....')</script>";
        }
    }
?>

这是我的index.php,我跳转到individual_home或organization_home。它工作正常。

<?php
session_start();
include("includes/connection.php"); 
?>
<div class="menu header">
  <div class="navbar-wrapper">
    <div class="container"> 
      <!-- Navbar start -->
      <div class="navwrapper">
        <div class="navbar navbar-inverse navbar-static-top">
          <div class="container fixed-nav-bar">
            <div class="logo"><a href="#"><img src="images/FONTS-FOR-PORTALS.jpg" style="width: 15%; !important"></a>
                <div class="pull-right">                    
                    <!-- <a href="#"><font style="color:Blue;font-size:15px;">Home</font></a>
                    <font style="color:Blue;font-size:15px;">|</font>
                    <a href="#"><font style="color:Blue;font-size:15px;">About Us</font></a>
                    <font style="color:Blue;font-size:15px;">|</font>
                    <a href="#"><font style="color:Blue;font-size:15px;">Contact Us</font></a>-->
                    <?php                       
                        if(!isset($_SESSION['email']))
                        {

                            echo '<a href="index.php"><font style="color:Blue;font-size:15px;">Home</font></a>';
                            echo '<font style="color:Blue;font-size:15px;">|</font>';
                            echo '<a href="about_us.php"><font style="color:Blue;font-size:15px;">about Us</font></a>';
                            echo '<font style="color:Blue;font-size:15px;">|</font>';
                            echo '<a href="contact_us.php"><font style="color:Blue;font-size:15px;">Contact Us</font></a>';

                        }                   
                        if(isset($_SESSION['email']))  


                        {
                            echo '<a href="individual_home.php"><font style="color:Blue;font-size:15px;">Home</font></a>';
                            echo '<font style="color:Blue;font-size:15px;">|</font>';
                            echo '<a href="about_us.php"><font style="color:Blue;font-size:15px;">about Us</font></a>';
                            echo '<font style="color:Blue;font-size:15px;">|</font>';
                            echo '<a href="contact_us.php"><font style="color:Blue;font-size:15px;">Contact Us</font></a>';
                            echo '<font style="color:Blue;font-size:15px;">|</font>';
                            echo '<a href="logout.php"><font style="color:Blue;font-size:15px;">Logout</font></a>';
                        }               

                    ?>                                          
                </div>                      
            </div>


          </div>
        </div>
      </div>
      <!-- Navbar end --> 

    </div>
  </div>
</div>

第二个是我的header.php如果我使用个人帐户登录它应该添加home | about us |个人家庭联系人和oraganizatin页面相同。 我的问题是我无法在header.php上创建用户类型的会话,请帮助我创建个人和组织页面的用户类型的会话。我有我的表名字'reg_type',它有2个用户类型1.individual 2.corporate

0 个答案:

没有答案