douzhuoxia0587 2015-09-25 15:23
浏览 7
已采纳

基于使用的凭据的基本用户重定向[关闭]

I'm setting up a plain HTML/PHP(to perform include()) website for demo purposes strictly. I'd like to make a functional login page that redirects the user based on the credentials used.

For example: If the user/pass combination used was "editor" and "123456" respectively, then he will be redirected to /editor.html. The same for "admin" and "user" members...

Certainly I already have the basic login layout in HTML, but how can I make it functional that way? How could I achieve this effectively?

Thank you very much for your time, Regards

Html code

<div id="pane-login" class="panel-body active">
      <div class="form-group">
        <div class="inputer">
          <div class="input-wrapper">
            <input type="text" class="form-control" placeholder="User">
          </div>
        </div>
      </div>
      <!--.form-group-->

      <div class="form-group">
        <div class="inputer">
          <div class="input-wrapper">
            <input type="password" class="form-control" placeholder="Pass">
          </div>
        </div>
      </div>
      <!--.form-group-->

      <div class="form-buttons clearfix">
        <label class="pull-left">
          <input type="checkbox" name="remember" value="1">
          Remember</label>
        <button type="submit" onclick="location.href='index.php';" class="btn btn-success pull-right">Enter</button>
      </div>
      <!--.form-buttons-->
    </div>
  • 写回答

2条回答 默认 最新

  • dongyi1921 2015-09-25 15:46
    关注

    Okay so first of all, your form isn't actually a form here.

    Prepend to the inputs:

     <form name="formname" method="POST" action="yourphpfile.php">
    

    and end with a

     </form>
    

    Add a "name" value to each of the inputs Remove the onClick from your submit Button.

    In your php file, do the following:

    $username = $_POST["firstinputname"]
    $password = $_POST["password"]
    

    Evaluate the login info and do a switch case in case login is correct;

    switch($username)
    {
        case "editor":
              header('Location: /yourlocation.php');
              break;
    
        case "another":
              header('Location: /anotherlocation.php');
              break;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像