doushi5752 2018-11-12 12:24
浏览 57

多个表的用户身份验证

I have a login screen that can authenticate "users" on my web app. But i also want to reuse the same login for "customers". Its an e-commerce type of web application. I am using PHP and MYSQL mainly to do my login authentication using one table.Below is my current code for verifying "users":

//Query statement for selecting details from database
$Sql = "SELECT * FROM users WHERE email = '".$user_name."' AND password = '".$password."'";
  • 写回答

2条回答 默认 最新

  • dpxua26604 2018-11-12 13:22
    关注

    Leaving coding part on your just demonstrating login in short. create column user_type in the users table.

    Method 1: -

    $Sql = "SELECT * FROM users WHERE email = '".$user_name."' AND password = '".$password."'";
    
    
    if($sql['user_type']=="customer"){
    
    $sql2 = "select * from customers";
    }
    

    now use session to store customer fields.

    You can also redirect to different pages

    if( $user == 1){ //check if user or password is correct from query
    
    
     if($user_type == "customer"){ //check usertype
    
        header("Location:/application/app.php"); //if normal user redirect to app.php
    
        }else{
    
        header("Location:/administration/admin.php"); //if admin user redirect to admin.php
    
        }
    }
    

    [follow this link for tutorials : link1]1

    [follow this link for tutorials : link2]2

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)