当前位置: 首页 > 知识库问答 >
问题:

html重定向到php

巫马山
2023-03-14

我有一个超文本标记语言登录页面,其中我有一个管理和用户的单选按钮,根据它,如果用户选择管理员,那么它应该重定向到管理员登录页面,如果他选择用户,那么它应该转到用户登录页面。

html登录页面如下:

<!-- THE LOG IN PAGE -->
<div id="id01" class="modal">  
    <form name="login" id="login" class="modal-content animate" action="login.php" method="post">
        <div class="imgcontainer">
            <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>
            <img src="images/avatar.png" alt="Avatar" class="avatar">
        </div>
        <div class="container">
            <label><b>Email Id:</b></label>
            <input type="text" placeholder="Enter Email Id" name="email" id="email" required>
            <label><b>Password:</b></label>
            <input type="password" placeholder="Enter Password" name="psw" id="psw" required> 
            <label><b>User Type:</b></label>
            <table width="100%">
            <tr>
            <td><input type="radio" name="usertype" id="usertype" value="admin" required>ADMIN</td>
            <td><input type="radio" name="usertype" id="usertype" value="user" required>USER</td>
            </tr>
            </table>            
            <button type="submit">Login</button>
            <input type="checkbox" checked="checked"> Remember me
            <span class="psw"><a href="#">Forgot password?</a></span>
            <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
        </div>
    </form>
    <script>
        // Get the modal
        var modal = document.getElementById('id01');
        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) 
        {
            if (event.target == modal) 
            {
                modal.style.display = "none";
            }
        }
    </script>
</div>

用户的admin_login.php页面如下所示:

<?php

会话_start();

$email=$_POST["email"];

$psw=$_POST["psw"];

$name=“”;

包括db_config.php;

$sql=“选择名称、密码、来自管理员的电子邮件\u详细信息,其中电子邮件='$email';

$result=$conn-

如果($结果)-

{

// output data of each row

while($row = $result->fetch_assoc()) 

{

    $name=$row['name'];

    if($psw == $row['password'])

    {

        $_SESSION['name']=$name;    

        $_SESSION['email']=$email;  

        header('Location: admin_index.php');

    }   

    else

    {

        echo '<script type="text/javascript">'; 

        echo 'alert("WRONG PASSWORD ENTRY. TRY LOGGING IN AGAIN !!!" );'; 

        echo 'window.location.href = "admin_index.php";';

        echo '</script>';           

    }

}

}

其他的

{

echo '<script type="text/javascript">';

echo 'alert("You must REGISTER first and then LOGIN !!!" );'; 

echo 'window.location.href = "admin_index.php";';

echo '</script>';

}

$con-

共有3个答案

顾泰平
2023-03-14

首先,在单选按钮中添加和处理程序:

<td><input type="radio" name="usertype" id="usertype" value="admin" required>ADMIN</td>
<td><input type="radio" name="usertype" id="usertype" value="user" required>USER</td>

<td><input type="radio" name="usertype" id="usertype" onclick="handleUserTypeChanges(this);" value="admin" required>ADMIN</td>
<td><input type="radio" name="usertype" id="usertype" onclick="handleUserTypeChanges(this);" value="user" required>USER</td>

然后你可以使用一些js,比如:

<script type="text/javascript">
    function handleUserTypeChanges(radioButton){
        var form = document.getElementById("login");
        var userType = radioButton.value;

        if (userType == 'admin') {
            form.action = 'your/path/to/admin/page/admin.php';
        }else{
            form.action = 'your/path/to/user/page/user.php';
        }
    }
</script>
刘海
2023-03-14

在login.php文件上使用此代码,希望它会有所帮助。

if(isset($_POST['email']))
{

if($_POST['usertype']=='admin') header('location: admin.php');
else if($_POST['usertype']=='user') header('location: user.php');
exit();

}
岳高明
2023-03-14

你可以用这样的东西。检查用户类型并相应地重定向

if(isset($_POST['login'])){
   // your code to check email id and password
    if($_POST['usertype'] == 'admin'){
        header('Location: admin.php');          
    }elseif($_POST['usertype'] == 'user'){
        header('Location: user.php');       
    }else{
        $error = "Invalid Login";           
    }       
}
 类似资料:
  • 问题内容: 是否可以设置基本的HTML页面以在加载时重定向到另一个页面? 问题答案: 尝试使用: 注意:将其放在头部。 此外,对于较旧的浏览器,如果添加了快速链接以防刷新不正确,请执行以下操作: 将显示为 重新导向 仍然可以通过单击几下到达目的地。

  • 问题内容: 我想使用PHP将所有www.domain.com请求重定向到domain.com,基本上是: 但是我确实想像SO中那样维护请求的URL,例如: 应该重定向到: 我不想依靠解决方案,并且我不确定要使用哪种变体来实现这一目标。同样,保留HTTPS协议将是一个加号。 我应该怎么做? 问题答案: 将用户重定向到完全相同的页面,www。完整。 因此,要摆脱www。,我们只需替换一行: 那应该起作

  • 隐私设置->清除浏览数据(从时间开始) https/ssl->管理证书->删除所有项(包括证书) 检查没有书签。 Firefox也有类似的问题,但它的解决方案不适用于Chrome。有人对我能做些什么有什么建议吗?提前感谢您的帮助!

  • 我正在使用Firefox,在设置服务器时,我一直在摆弄重定向。现在,Firefox已经缓存了从http://example.com/到https://example.com/和从http://sub.example.com/到https://sub.example.com/的301重定向。 我已经尝试了以下几件事: null 我的Firefox版本是38.0.1,我使用的是Windows8.1。我

  • 重定向到一个 URL 。 使用 window.location.href 或 window.location.replace() 重定向到 url 。 传递第二个参数来模拟链接点击(true - 默认值)或HTTP重定向(false)。 const redirect = (url, asLink = true) => asLink ? (window.location.href = url)

  • 问题内容: 我在cyberciti.biz的评论中看到了这个有趣的问题。 我发现我什至找不到在sh的单行命令中执行此操作的灵活方法。 到目前为止,我对解决方案的想法是: 但是您会看到,这不是同步的,而且致命的是,它是如此丑陋。 欢迎与您分享这个想法。:) 问题答案: 你要 这里的顺序很重要。假设stdin(fd 0),stdout(fd 1)和stderr(fd 2)最初都连接到tty,因此 首先