我有一個HTML登錄頁面,其中有一個管理員和用戶的單選按鈕,如果用戶選擇「管理員」,那麼它應該重定向到管理員登錄頁面,如果他選擇「用戶」那麼就應該到用戶登錄頁面html重定向到php
如下面給出的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">×</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
在session_start() ;
$ email = $ _ POST [「email」];
$ psw = $ _ POST [「psw」];
$ name =「」;
include'db_config.php';
$ sql =「SELECT name,password,email FROM admin_details where email ='$ email'」;
$ result = $ conn-> query($ sql);
如果($ result-> NUM_ROWS> 0)
{
// 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>';
}
$ conn-> close();
>
其中是您的PHP腳本用於重定向? –
有兩種方法,無論是使用Javascript或PHP(獲取元素值,相應地進行比較和重定向) –
男人,這是痛苦的眼睛...請嘗試扔它通過在線格式化器或東西,請。這一個是相當不錯的,我想http://www.freeformatter.com/html-formatter.html –